<?php
namespace App\Entity\Order;
use App\Entity\Coupons\CouponDiscount;
use App\Entity\Coupons\CouponSingleUse;
use App\Entity\File;
use App\Entity\Package\Package;
use App\Entity\Traits\IdTrait;
use App\Entity\Traits\TimeStampAbleTrait;
use App\Entity\User\User;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\Order\OrdersRepository;
/**
* @ORM\Entity(repositoryClass=OrdersRepository::class)
*/
class Orders
{
use IdTrait;
use TimeStampAbleTrait;
public const STATUS_GREEN = 'text-success';
public const STATUS_RED = 'text-alert';
public const STATUS_YELLOW = 'text-warning';
public const STATUS_CIRCLE_GREEN = 'limegreen';
public const STATUS_CIRCLE_RED = 'red';
// Brak
public const LACK = 0;
// Odrzucony
public const REJECTED = 1;
// Płatny
public const PAID = 2;
private const ONLINE = 0;
private const TRADITIONAL_TRANSFER = 1;
private const ACTIVE = 1;
private const NO_ACTIVE = 0;
public const STATUS = [
self::NO_ACTIVE => [
'text' => 'ADMIN.ORDER.STATUS_TYPE.0',
'value' => 0,
],
self::ACTIVE => [
'text' => 'ADMIN.ORDER.STATUS_TYPE.1',
'value' => 1,
],
];
public const METHOD_PAYMENT_TYPE = [
self::ONLINE => [
'text' => 'Online',
'value' => 0,
],
self::TRADITIONAL_TRANSFER => [
'text' => 'Przelew tradycyjny',
'value' => 1,
],
];
public const OFFER_STATUS = [
self::NO_ACTIVE => [
'text' => 'Oczekująca',
'value' => self::NO_ACTIVE,
],
self::ACTIVE => [
'text' => 'Przeterminowana',
'value' => self::ACTIVE,
],
];
public const PAYMENT_TYPE = [
self::LACK => [
'text' => 'ADMIN.ORDER.PAYMENT_TYPE_STATUS.0',
'value' => 0,
],
self::REJECTED => [
'text' => 'ADMIN.ORDER.PAYMENT_TYPE_STATUS.1',
'value' => 1,
],
self::PAID => [
'text' => 'ADMIN.ORDER.PAYMENT_TYPE_STATUS.2',
'value' => 2,
],
];
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $isSendInvoice = false;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $isSendInvoiceProForm = false;
/**
* @ORM\Column(type="string", length="255", nullable=true)
*/
private ?string $offerStatus = null;
public function __construct(
/**
* @ORM\ManyToOne(targetEntity=User::class)
*/
private ?User $user = null,
/**
* @ORM\ManyToOne(targetEntity=Package::class)
*/
private ?Package $package = null,
/**
* @ORM\Column(type="string", length="255", nullable=true)
*/
private ?string $status = null,
/**
* @ORM\Column(type="string", length="255", nullable=true)
*/
private ?string $paymentStatus = null,
/**
* @ORM\Column(type="float", nullable=true)
*/
private ?float $priceNet = 0.00,
/**
* @ORM\Column(type="float", nullable=true)
*/
private ?float $priceGross = 0.00,
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $isRange = false,
/**
* @ORM\Column(type="integer", nullable=true)
*/
private ?int $numberLocalization = null,
/**
* @ORM\Column(type="json", nullable=true)
*/
private ?array $industriesIds = null,
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $isUsedCodeDiscount = false,
/**
* @ORM\ManyToOne(targetEntity=CouponDiscount::class)
*/
private ?CouponDiscount $couponDiscount = null,
/**
* @ORM\ManyToOne(targetEntity=CouponSingleUse::class)
*/
private ?CouponSingleUse $couponSingleUse = null,
/**
* @ORM\Column(type="json", nullable=true)
*/
private ?array $invoice = [],
/**
* @ORM\Column(type="json", nullable=true)
*/
private ?array $payment = [],
/**
* @ORM\Column(type="json", nullable=true)
*/
private ?array $configuration = [],
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $uuid = null,
/**
* @ORM\ManyToOne(targetEntity=File::class)
*/
private ?File $invoiceFile = null,
/**
* @ORM\ManyToOne(targetEntity=File::class)
*/
private ?File $invoiceProFormFile = null,
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private ?bool $needToAccepted = false,
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private ?DateTime $expiredAt = null,
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $currency = null,
){}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getPackage(): ?Package
{
return $this->package;
}
public function setPackage(?Package $package): self
{
$this->package = $package;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(?string $status): self
{
$this->status = $status;
return $this;
}
public function isActive(): bool
{
return $this->getStatus() == '1' && $this->getPaymentStatus() == '2';
}
public function getPaymentStatus(): ?string
{
return $this->paymentStatus;
}
public function setPaymentStatus(?string $paymentStatus): self
{
$this->paymentStatus = $paymentStatus;
return $this;
}
public function getPriceNet(): ?float
{
return $this->priceNet;
}
public function setPriceNet(?float $priceNet): self
{
$this->priceNet = $priceNet;
return $this;
}
public function getPriceGross(): ?float
{
return $this->priceGross;
}
public function setPriceGross(?float $priceGross): self
{
$this->priceGross = $priceGross;
return $this;
}
public function getIsRange(): ?bool
{
return $this->isRange;
}
public function setIsRange(?bool $isRange): self
{
$this->isRange = $isRange;
return $this;
}
public function getNumberLocalization(): ?int
{
return $this->numberLocalization;
}
public function setNumberLocalization(?int $numberLocalization): self
{
$this->numberLocalization = $numberLocalization;
return $this;
}
public function getIndustriesIds(): ?array
{
return $this->industriesIds;
}
public function setIndustriesIds(?array $industriesIds): self
{
$this->industriesIds = $industriesIds;
return $this;
}
public function getIsUsedCodeDiscount(): ?bool
{
return $this->isUsedCodeDiscount;
}
public function setIsUsedCodeDiscount(?bool $isUsedCodeDiscount): self
{
$this->isUsedCodeDiscount = $isUsedCodeDiscount;
return $this;
}
public function getCouponDiscount(): ?CouponDiscount
{
return $this->couponDiscount;
}
public function setCouponDiscount(?CouponDiscount $couponDiscount): self
{
$this->couponDiscount = $couponDiscount;
return $this;
}
public function getCouponSingleUse(): ?CouponSingleUse
{
return $this->couponSingleUse;
}
public function setCouponSingleUse(?CouponSingleUse $couponSingleUse): self
{
$this->couponSingleUse = $couponSingleUse;
return $this;
}
public function getInvoice(): ?array
{
return $this->invoice;
}
public function setInvoice(?array $invoice): self
{
$this->invoice = $invoice;
return $this;
}
public function getPayment(): ?array
{
return $this->payment;
}
public function setPayment(?array $payment): self
{
$this->payment = $payment;
return $this;
}
public function getConfiguration(): ?array
{
return $this->configuration;
}
public function setConfiguration(?array $configuration): self
{
$this->configuration = $configuration;
return $this;
}
public function getUuid(): ?string
{
return $this->uuid;
}
public function setUuid(?string $uuid): self
{
$this->uuid = $uuid;
return $this;
}
public function generateUuid(): void
{
$date = new DateTime();
$uuid = $date->format('Ymdhis');
$this->setUuid($uuid);
}
public function getInvoiceFile(): ?File
{
return $this->invoiceFile;
}
public function setInvoiceFile(?File $invoiceFile): self
{
$this->invoiceFile = $invoiceFile;
return $this;
}
public function getInvoiceProFormFile(): ?File
{
return $this->invoiceProFormFile;
}
public function setInvoiceProFormFile(?File $invoiceProFormFile): self
{
$this->invoiceProFormFile = $invoiceProFormFile;
return $this;
}
public function getIsSendInvoice(): ?bool
{
return $this->isSendInvoice;
}
public function setIsSendInvoice(?bool $isSendInvoice): self
{
$this->isSendInvoice = $isSendInvoice;
return $this;
}
public function getIsSendInvoiceProForm(): ?bool
{
return $this->isSendInvoiceProForm;
}
public function setIsSendInvoiceProForm(?bool $isSendInvoiceProForm): self
{
$this->isSendInvoiceProForm = $isSendInvoiceProForm;
return $this;
}
public function getNeedToAccepted(): ?bool
{
return $this->needToAccepted;
}
public function setNeedToAccepted(?bool $needToAccepted): self
{
$this->needToAccepted = $needToAccepted;
return $this;
}
public function getExpiredAt(): ?DateTime
{
return $this->expiredAt;
}
public function setExpiredAt(?DateTime $expiredAt): self
{
$this->expiredAt = $expiredAt;
return $this;
}
public function getOfferStatus(): ?string
{
return $this->offerStatus;
}
public function setOfferStatus(?string $offerStatus): self
{
$this->offerStatus = $offerStatus;
return $this;
}
public function getCurrency(): ?string
{
return $this->currency;
}
public function setCurrency(?string $currency): self
{
$this->currency = $currency;
return $this;
}
public function setParamInConfiguration(string $key, string $value): void
{
if(key_exists($key, $this->configuration)){
$this->configuration[$key] = $value;
}else{
$this->configuration[] = [$key => $value];
}
}
public function checkIsUsed(): bool
{
$numberAds = (int) $this->getConfiguration()['number_ads'] ?? 0;
$usedAds = (int) $this->getConfiguration()['number_used_ads'] ?? 0;
return ($usedAds >= $numberAds);
}
public function getStatusPaymentColor(): string
{
if ($this->getPaymentStatus() === "0") {
return self::STATUS_YELLOW;
}
if ($this->getPaymentStatus() === "2") {
return self::STATUS_GREEN;
}
return self::STATUS_RED;
}
public function getStatusColor(): string
{
if ($this->getStatus()) {
return self::STATUS_GREEN;
}
return self::STATUS_RED;
}
public function getStatusCircleColor(): string
{
if ($this->getStatus()) {
return self::STATUS_CIRCLE_GREEN;
}
return self::STATUS_CIRCLE_RED;
}
public function getParamFromConfiguration(string $key, $format): mixed
{
$param = null;
if (isset($this->configuration[$key])) {
$param = $this->configuration[$key];
}
if ($format === 'int') {
return (int) $param;
}
if ($format === 'float') {
return (float) $param;
}
if ($format === 'bool') {
return (bool) $param;
}
return $param;
}
}