src/Entity/Order/Orders.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Order;
  3. use App\Entity\Coupons\CouponDiscount;
  4. use App\Entity\Coupons\CouponSingleUse;
  5. use App\Entity\File;
  6. use App\Entity\Package\Package;
  7. use App\Entity\Traits\IdTrait;
  8. use App\Entity\Traits\TimeStampAbleTrait;
  9. use App\Entity\User\User;
  10. use DateTime;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use App\Repository\Order\OrdersRepository;
  13. /**
  14.  * @ORM\Entity(repositoryClass=OrdersRepository::class)
  15.  */
  16. class Orders
  17. {
  18.   use IdTrait;
  19.   use TimeStampAbleTrait;
  20.     public const STATUS_GREEN = 'text-success';
  21.     public const STATUS_RED = 'text-alert';
  22.     public const STATUS_YELLOW = 'text-warning';
  23.     public const STATUS_CIRCLE_GREEN = 'limegreen';
  24.     public const STATUS_CIRCLE_RED = 'red';
  25.   // Brak
  26.     public const LACK = 0;
  27.   // Odrzucony
  28.     public const REJECTED = 1;
  29.   // Płatny
  30.     public const PAID = 2;
  31.     private const ONLINE = 0;
  32.     private const TRADITIONAL_TRANSFER = 1;
  33.     private const ACTIVE = 1;
  34.     private const NO_ACTIVE = 0;
  35.     public const STATUS = [
  36.         self::NO_ACTIVE => [
  37.               'text' => 'ADMIN.ORDER.STATUS_TYPE.0',
  38.               'value' => 0,
  39.         ],
  40.         self::ACTIVE => [
  41.               'text' => 'ADMIN.ORDER.STATUS_TYPE.1',
  42.               'value' => 1,
  43.         ],
  44.       ];
  45.     public const METHOD_PAYMENT_TYPE = [
  46.         self::ONLINE => [
  47.             'text' => 'Online',
  48.             'value' => 0,
  49.         ],
  50.         self::TRADITIONAL_TRANSFER => [
  51.           'text' => 'Przelew tradycyjny',
  52.           'value' => 1,
  53.        ],
  54.     ];
  55.     public const OFFER_STATUS = [
  56.         self::NO_ACTIVE => [
  57.               'text' => 'Oczekująca',
  58.               'value' => self::NO_ACTIVE,
  59.         ],
  60.         self::ACTIVE => [
  61.               'text' => 'Przeterminowana',
  62.               'value' => self::ACTIVE,
  63.         ],
  64.       ];
  65.     public const PAYMENT_TYPE = [
  66.         self::LACK => [
  67.             'text' => 'ADMIN.ORDER.PAYMENT_TYPE_STATUS.0',
  68.             'value' => 0,
  69.         ],
  70.         self::REJECTED => [
  71.           'text' => 'ADMIN.ORDER.PAYMENT_TYPE_STATUS.1',
  72.           'value' => 1,
  73.         ],
  74.         self::PAID => [
  75.           'text' => 'ADMIN.ORDER.PAYMENT_TYPE_STATUS.2',
  76.           'value' => 2,
  77.         ],
  78.     ];
  79.     /**
  80.      * @ORM\Column(type="boolean", nullable=true)
  81.      */
  82.     private ?bool $isSendInvoice = false;
  83.     /**
  84.      * @ORM\Column(type="boolean", nullable=true)
  85.      */
  86.     private ?bool $isSendInvoiceProForm = false;
  87.     /**
  88.      * @ORM\Column(type="string", length="255", nullable=true)
  89.      */
  90.     private ?string $offerStatus = null;
  91.     public function __construct(
  92.       /**
  93.        * @ORM\ManyToOne(targetEntity=User::class)
  94.        */
  95.       private ?User $user = null,
  96.       /**
  97.        * @ORM\ManyToOne(targetEntity=Package::class)
  98.        */
  99.       private ?Package $package = null,
  100.       /**
  101.        * @ORM\Column(type="string", length="255", nullable=true)
  102.        */
  103.       private ?string $status = null,
  104.       /**
  105.        * @ORM\Column(type="string", length="255", nullable=true)
  106.        */
  107.       private ?string $paymentStatus = null,
  108.       /**
  109.        * @ORM\Column(type="float", nullable=true)
  110.        */
  111.       private ?float $priceNet = 0.00,
  112.       /**
  113.        * @ORM\Column(type="float", nullable=true)
  114.        */
  115.       private ?float $priceGross = 0.00,
  116.       /**
  117.        * @ORM\Column(type="boolean", nullable=true)
  118.        */
  119.       private ?bool $isRange = false,
  120.       /**
  121.        * @ORM\Column(type="integer", nullable=true)
  122.        */
  123.       private ?int $numberLocalization = null,
  124.         /**
  125.          * @ORM\Column(type="json", nullable=true)
  126.          */
  127.       private ?array $industriesIds = null,
  128.       /**
  129.        * @ORM\Column(type="boolean", nullable=true)
  130.        */
  131.       private ?bool $isUsedCodeDiscount = false,
  132.       /**
  133.        * @ORM\ManyToOne(targetEntity=CouponDiscount::class)
  134.        */
  135.       private ?CouponDiscount $couponDiscount = null,
  136.       /**
  137.        * @ORM\ManyToOne(targetEntity=CouponSingleUse::class)
  138.        */
  139.       private ?CouponSingleUse $couponSingleUse = null,
  140.       /**
  141.        * @ORM\Column(type="json", nullable=true)
  142.        */
  143.       private ?array $invoice = [],
  144.       /**
  145.        * @ORM\Column(type="json", nullable=true)
  146.        */
  147.       private ?array $payment = [],
  148.       /**
  149.        * @ORM\Column(type="json", nullable=true)
  150.        */
  151.       private ?array $configuration = [],
  152.       /**
  153.        * @ORM\Column(type="string", nullable=true)
  154.        */
  155.       private ?string $uuid = null,
  156.       /**
  157.        * @ORM\ManyToOne(targetEntity=File::class)
  158.        */
  159.       private ?File $invoiceFile = null,
  160.       /**
  161.        * @ORM\ManyToOne(targetEntity=File::class)
  162.        */
  163.       private ?File $invoiceProFormFile = null,
  164.       /**
  165.        * @ORM\Column(type="boolean", nullable=true)
  166.        */
  167.       private ?bool $needToAccepted = false,
  168.       /**
  169.         * @ORM\Column(type="datetime", nullable=true)
  170.         */
  171.       private ?DateTime $expiredAt = null,
  172.       /**
  173.        * @ORM\Column(type="string", nullable=true)
  174.        */
  175.       private ?string $currency = null,
  176.   ){}
  177.     public function getUser(): ?User
  178.     {
  179.         return $this->user;
  180.     }
  181.     public function setUser(?User $user): self
  182.     {
  183.         $this->user = $user;
  184.         return $this;
  185.     }
  186.     public function getPackage(): ?Package
  187.     {
  188.         return $this->package;
  189.     }
  190.     public function setPackage(?Package $package): self
  191.     {
  192.         $this->package = $package;
  193.         return $this;
  194.     }
  195.     public function getStatus(): ?string
  196.     {
  197.         return $this->status;
  198.     }
  199.     public function setStatus(?string $status): self
  200.     {
  201.         $this->status = $status;
  202.         return $this;
  203.     }
  204.     public function isActive(): bool
  205.     {
  206.         return $this->getStatus() == '1' && $this->getPaymentStatus() == '2';
  207.     }
  208.     public function getPaymentStatus(): ?string
  209.     {
  210.         return $this->paymentStatus;
  211.     }
  212.     public function setPaymentStatus(?string $paymentStatus): self
  213.     {
  214.         $this->paymentStatus = $paymentStatus;
  215.         return $this;
  216.     }
  217.     public function getPriceNet(): ?float
  218.     {
  219.         return $this->priceNet;
  220.     }
  221.     public function setPriceNet(?float $priceNet): self
  222.     {
  223.         $this->priceNet = $priceNet;
  224.         return $this;
  225.     }
  226.     public function getPriceGross(): ?float
  227.     {
  228.         return $this->priceGross;
  229.     }
  230.     public function setPriceGross(?float $priceGross): self
  231.     {
  232.         $this->priceGross = $priceGross;
  233.         return $this;
  234.     }
  235.     public function getIsRange(): ?bool
  236.     {
  237.         return $this->isRange;
  238.     }
  239.     public function setIsRange(?bool $isRange): self
  240.     {
  241.         $this->isRange = $isRange;
  242.         return $this;
  243.     }
  244.     public function getNumberLocalization(): ?int
  245.     {
  246.         return $this->numberLocalization;
  247.     }
  248.     public function setNumberLocalization(?int $numberLocalization): self
  249.     {
  250.         $this->numberLocalization = $numberLocalization;
  251.         return $this;
  252.     }
  253.     public function getIndustriesIds(): ?array
  254.     {
  255.         return $this->industriesIds;
  256.     }
  257.     public function setIndustriesIds(?array $industriesIds): self
  258.     {
  259.         $this->industriesIds = $industriesIds;
  260.         return $this;
  261.     }
  262.     public function getIsUsedCodeDiscount(): ?bool
  263.     {
  264.         return $this->isUsedCodeDiscount;
  265.     }
  266.     public function setIsUsedCodeDiscount(?bool $isUsedCodeDiscount): self
  267.     {
  268.         $this->isUsedCodeDiscount = $isUsedCodeDiscount;
  269.         return $this;
  270.     }
  271.     public function getCouponDiscount(): ?CouponDiscount
  272.     {
  273.         return $this->couponDiscount;
  274.     }
  275.     public function setCouponDiscount(?CouponDiscount $couponDiscount): self
  276.     {
  277.         $this->couponDiscount = $couponDiscount;
  278.         return $this;
  279.     }
  280.     public function getCouponSingleUse(): ?CouponSingleUse
  281.     {
  282.         return $this->couponSingleUse;
  283.     }
  284.     public function setCouponSingleUse(?CouponSingleUse $couponSingleUse): self
  285.     {
  286.         $this->couponSingleUse = $couponSingleUse;
  287.         return $this;
  288.     }
  289.     public function getInvoice(): ?array
  290.     {
  291.         return $this->invoice;
  292.     }
  293.     public function setInvoice(?array $invoice): self
  294.     {
  295.         $this->invoice = $invoice;
  296.         return $this;
  297.     }
  298.     public function getPayment(): ?array
  299.     {
  300.         return $this->payment;
  301.     }
  302.     public function setPayment(?array $payment): self
  303.     {
  304.         $this->payment = $payment;
  305.         return $this;
  306.     }
  307.     public function getConfiguration(): ?array
  308.     {
  309.         return $this->configuration;
  310.     }
  311.     public function setConfiguration(?array $configuration): self
  312.     {
  313.         $this->configuration = $configuration;
  314.         return $this;
  315.     }
  316.     public function getUuid(): ?string
  317.     {
  318.         return $this->uuid;
  319.     }
  320.     public function setUuid(?string $uuid): self
  321.     {
  322.         $this->uuid = $uuid;
  323.         return $this;
  324.     }
  325.     public function generateUuid(): void
  326.     {
  327.         $date = new DateTime();
  328.         $uuid = $date->format('Ymdhis');
  329.         $this->setUuid($uuid);
  330.     }
  331.     public function getInvoiceFile(): ?File
  332.     {
  333.         return $this->invoiceFile;
  334.     }
  335.     public function setInvoiceFile(?File $invoiceFile): self
  336.     {
  337.         $this->invoiceFile = $invoiceFile;
  338.         return $this;
  339.     }
  340.     public function getInvoiceProFormFile(): ?File
  341.     {
  342.         return $this->invoiceProFormFile;
  343.     }
  344.     public function setInvoiceProFormFile(?File $invoiceProFormFile): self
  345.     {
  346.         $this->invoiceProFormFile = $invoiceProFormFile;
  347.         return $this;
  348.     }
  349.     public function getIsSendInvoice(): ?bool
  350.     {
  351.         return $this->isSendInvoice;
  352.     }
  353.     public function setIsSendInvoice(?bool $isSendInvoice): self
  354.     {
  355.         $this->isSendInvoice = $isSendInvoice;
  356.         return $this;
  357.     }
  358.     public function getIsSendInvoiceProForm(): ?bool
  359.     {
  360.         return $this->isSendInvoiceProForm;
  361.     }
  362.     public function setIsSendInvoiceProForm(?bool $isSendInvoiceProForm): self
  363.     {
  364.         $this->isSendInvoiceProForm = $isSendInvoiceProForm;
  365.         return $this;
  366.     }
  367.     public function getNeedToAccepted(): ?bool
  368.     {
  369.         return $this->needToAccepted;
  370.     }
  371.     public function setNeedToAccepted(?bool $needToAccepted): self
  372.     {
  373.         $this->needToAccepted = $needToAccepted;
  374.         return $this;
  375.     }
  376.     public function getExpiredAt(): ?DateTime
  377.     {
  378.         return $this->expiredAt;
  379.     }
  380.     public function setExpiredAt(?DateTime $expiredAt): self
  381.     {
  382.         $this->expiredAt = $expiredAt;
  383.         return $this;
  384.     }
  385.     public function getOfferStatus(): ?string
  386.     {
  387.         return $this->offerStatus;
  388.     }
  389.     public function setOfferStatus(?string $offerStatus): self
  390.     {
  391.         $this->offerStatus = $offerStatus;
  392.         return $this;
  393.     }
  394.     public function getCurrency(): ?string
  395.     {
  396.         return $this->currency;
  397.     }
  398.     public function setCurrency(?string $currency): self
  399.     {
  400.         $this->currency = $currency;
  401.         return $this;
  402.     }
  403.     public function setParamInConfiguration(string $key, string $value): void
  404.     {
  405.         if(key_exists($key, $this->configuration)){
  406.             $this->configuration[$key] = $value;
  407.         }else{
  408.             $this->configuration[] = [$key => $value];
  409.         }
  410.     }
  411.     public function checkIsUsed(): bool
  412.     {
  413.         $numberAds = (int) $this->getConfiguration()['number_ads'] ?? 0;
  414.         $usedAds = (int) $this->getConfiguration()['number_used_ads'] ?? 0;
  415.         return ($usedAds >= $numberAds);
  416.     }
  417.     public function getStatusPaymentColor(): string
  418.     {
  419.         if ($this->getPaymentStatus() === "0") {
  420.             return self::STATUS_YELLOW;
  421.         }
  422.         if ($this->getPaymentStatus() === "2") {
  423.             return self::STATUS_GREEN;
  424.         }
  425.         return self::STATUS_RED;
  426.     }
  427.     public function getStatusColor(): string
  428.     {
  429.         if ($this->getStatus()) {
  430.             return self::STATUS_GREEN;
  431.         }
  432.         return self::STATUS_RED;
  433.     }
  434.     public function getStatusCircleColor(): string
  435.     {
  436.         if ($this->getStatus()) {
  437.             return self::STATUS_CIRCLE_GREEN;
  438.         }
  439.         return self::STATUS_CIRCLE_RED;
  440.     }
  441.     public function getParamFromConfiguration(string $key, $format): mixed
  442.     {
  443.         $param = null;
  444.         if (isset($this->configuration[$key])) {
  445.             $param = $this->configuration[$key];
  446.         }
  447.         if ($format === 'int') {
  448.             return (int) $param;
  449.         }
  450.         if ($format === 'float') {
  451.             return (float) $param;
  452.         }
  453.         if ($format === 'bool') {
  454.             return (bool) $param;
  455.         }
  456.         return $param;
  457.     }
  458. }