src/Flexy/ShopBundle/Entity/Order/Order.php line 50
<?phpnamespace App\Flexy\ShopBundle\Entity\Order;use ApiPlatform\Core\Annotation\ApiFilter;use ApiPlatform\Core\Annotation\ApiResource;use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;use App\Entity\LogHistory;use App\Entity\User;use App\Flexy\ShopBundle\Entity\Accounting\Invoice;use App\Flexy\ShopBundle\Entity\Customer\Customer;use App\Flexy\ShopBundle\Entity\Payment\Payment;use App\Flexy\ShopBundle\Entity\Shipping\Shipment;use App\Flexy\ShopBundle\Entity\Customer\CustomerWalletPoint;use App\Flexy\ShopBundle\Entity\Payment\PaymentMethod;use App\Flexy\ShopBundle\Entity\Promotion\Coupon;use App\Flexy\ShopBundle\Entity\Shipping\CityRegion;use App\Flexy\ShopBundle\Entity\Resource\Agent;use App\Flexy\ShopBundle\Entity\Shipping\ShippingMethod;use App\Flexy\ShopBundle\Entity\Store\Store;use App\Flexy\ShopBundle\Entity\Vendor\Vendor;use App\Flexy\ShopBundle\Repository\Order\OrderRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;use Doctrine\ORM\Mapping\Entity;use Doctrine\ORM\Mapping\InheritanceType;use Gedmo\Mapping\Annotation as Gedmo;use Symfony\Component\Serializer\Annotation\Groups;use Symfony\Component\Validator\Constraints as Assert;use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;#[ApiResource(normalizationContext: ['groups' => ['read']],denormalizationContext: ['groups' => ['write']],)]#[ApiFilter(SearchFilter::class, properties: ['status' => 'exact','customer'=>'exact'])]#[ORM\Table(name: '`order`')]#[ORM\Entity(repositoryClass: OrderRepository::class)]#[InheritanceType('JOINED')]#[Gedmo\SoftDeleteable(fieldName: 'deletedAt', timeAware: false, hardDelete: true)]#[Gedmo\Loggable(logEntryClass:LogHistory::class)]#[UniqueEntity(fields: ['reference'],errorPath: 'reference',message: 'This reference is already exist.',)]class Order implements \Stringable{#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column(type: 'integer')]#[Groups(['read'])]private $id;#[Groups(['read'])]#[ORM\Column(type: 'datetime', nullable: true)]private ?\DateTime $createdAt = null;#[Groups(['read','write'])]#[ORM\Column(type: 'text', nullable: true)]#[Gedmo\Versioned]private ?string $description = null;#[Groups(['read','write'])]#[ORM\ManyToOne(targetEntity: Customer::class, inversedBy: 'orders', cascade: ['persist'])]#[Assert\Valid]#[Gedmo\Versioned]private ?\App\Flexy\ShopBundle\Entity\Customer\Customer $customer = null;#[Groups(['read','write'])]#[ORM\OneToMany(targetEntity: OrderItem::class, mappedBy: 'parentOrder', cascade: ['persist', 'remove'])]#[Assert\Valid]private \Doctrine\Common\Collections\Collection|array $orderItems;#[ORM\OneToMany(targetEntity: Adjustment::class, mappedBy: 'parentOrder')]private \Doctrine\Common\Collections\Collection|array $adjustments;#[ORM\Column(type: 'string', length: 255, nullable: true)]#[Groups(['read','write'])]private ?string $firstName = null;#[ORM\Column(type: 'string', length: 255, nullable: true)]#[Groups(['read','write'])]private ?string $lastName = null;#[ORM\Column(type: 'string', length: 255, nullable: true)]#[Groups(['read','write'])]private ?string $companyName = null;#[ORM\Column(type: 'string', length: 255, nullable: true)]#[Groups(['read','write'])]private ?string $address = null;#[ORM\Column(type: 'string', length: 255, nullable: true)]#[Groups(['read','write'])]private ?string $city = null;#[ORM\Column(type: 'string', length: 255, nullable: true)]#[Groups(['read','write'])]private ?string $country = null;#[ORM\Column(type: 'string', length: 255, nullable: true)]private ?string $department = null;#[ORM\Column(type: 'string', length: 255, nullable: true)]private ?string $postcode = null;#[ORM\Column(type: 'string', length: 255, nullable: true)]#[Groups(['read','write'])]private ?string $email = null;#[ORM\Column(type: 'string', length: 255, nullable: true)]#[Groups(['read','write'])]private ?string $tel = null;#[ORM\Column(type: 'text', nullable: true)]private ?string $comment = null;#[ORM\ManyToOne(targetEntity: DemandeFund::class, inversedBy: 'orders')]private ?\App\Flexy\ShopBundle\Entity\Order\DemandeFund $demandeFund = null;#[Groups(['read','write'])]#[ORM\Column(type: 'string', length: 255, nullable: true)]#[Gedmo\Versioned]private ?string $status = "draft";#[ORM\Column(type: 'string', length: 255, nullable: true)]private ?string $source = null;#[ORM\Column(type: 'text', nullable: true)]private $deliveryAt;#[ORM\Column(type: 'text', nullable: true)]private $recoveryAt;#[ORM\Column(type: 'string', length: 255, nullable: true)]private ?string $oldOrderNumber = null;#[ORM\Column(type: 'float', nullable: true)]private ?float $reduction = null;#[ORM\Column(type: 'float', nullable: true)]private $distance = 0;#[ORM\ManyToOne(targetEntity: ShippingMethod::class, inversedBy: 'orders', cascade: ['persist'])]#[Groups(['read','write'])]#[Gedmo\Versioned]private ?\App\Flexy\ShopBundle\Entity\Shipping\ShippingMethod $shippingMethod = null;#[ORM\ManyToOne(targetEntity: Agent::class, inversedBy: 'orders')]#[Groups(['read','write'])]#[Gedmo\Versioned]private ?\App\Flexy\ShopBundle\Entity\Resource\Agent $agent = null;#[Groups(['read','write'])]#[ORM\ManyToOne(targetEntity: paymentMethod::class, inversedBy: 'orders', cascade: ['persist'])]#[ORM\JoinColumn(nullable: true, onDelete: 'CASCADE')]private ?\App\Flexy\ShopBundle\Entity\Payment\PaymentMethod $paymentMethod = null;#[ORM\Column(type: 'float', nullable: true)]#[Groups(['read','write'])]#[Gedmo\Versioned]private ?float $payedAmount = null;#[ORM\Column(type: 'datetime', nullable: true)]#[Groups(['read','write'])]#[Gedmo\Versioned]private ?\DateTimeInterface $startProcessingAt = null;#[ORM\Column(type: 'string', length: 255, nullable: true)]private ?string $deliveryType = null;#[ORM\Column(type: 'datetime', nullable: true)]#[Groups(['read','write'])]#[Gedmo\Versioned]private ?\DateTimeInterface $startDeliveryAt = null;#[ORM\OneToMany(targetEntity: CustomerWalletPoint::class, mappedBy: 'originOrder')]private \Doctrine\Common\Collections\Collection|array $customerWalletPoints;#[ORM\ManyToOne(targetEntity: Coupon::class, inversedBy: 'orders')]#[Groups(['read','write'])]private ?\App\Flexy\ShopBundle\Entity\Promotion\Coupon $coupon = null;#[ORM\ManyToOne(targetEntity: Agent::class, inversedBy: 'ordersToDolist')]private ?\App\Flexy\ShopBundle\Entity\Resource\Agent $agentToDo = null;#[ORM\Column(type: 'boolean', nullable: true)]private ?bool $isToDo = null;#[ORM\ManyToOne(targetEntity: CityRegion::class, inversedBy: 'orders')]private ?\App\Flexy\ShopBundle\Entity\Shipping\CityRegion $cityRegionShipping = null;#[ORM\ManyToOne(targetEntity: CityRegion::class, inversedBy: 'collectedOrders')]private $cityRegionCollect;#[ORM\ManyToOne(targetEntity: Vendor::class, inversedBy: 'orders')]private ?\App\Flexy\ShopBundle\Entity\Vendor\Vendor $vendor = null;#[ORM\Column(type: 'text', nullable: true)]#[Groups(['read','write'])]private ?string $collectAddress = null;#[ORM\Column(type: 'text', nullable: true)]#[Groups(['read','write'])]private ?string $shippingAddress = null;#[ORM\Column(type: 'string', length: 255, nullable: true)]#[Groups(['read','write'])]private ?string $collectTel = null;#[ORM\Column(type: 'boolean', nullable: true)]#[Groups(['read','write'])]private ?bool $isHeavy = null;#[ORM\Column(type: 'float', nullable: true)]private $shippingTips = 0;#[ORM\Column(type: 'float', nullable: true)]private $walletPaymentAmount = 0;#[ORM\Column(type: 'boolean', nullable: true)]private $isChecked;#[ORM\Column(type: 'string', length: 255, nullable: true)]private $tokenStripe;#[ORM\Column(length: 255, nullable: true)]private ?string $orderType = "order";#[ORM\Column(nullable: true)]private ?\DateTimeImmutable $deletedAt = null;#[ORM\ManyToOne(inversedBy: 'orders')]private ?Store $store = null;#[ORM\OneToOne(inversedBy: 'relatedOrder', cascade: ['persist', 'remove'])]private ?Shipment $shipment = null;#[ORM\ManyToOne(inversedBy: 'orders')]private ?Invoice $invoice = null;#[ORM\Column(type: Types::STRING,nullable: true)]#[Gedmo\Blameable(on: 'create')]private $createdBy;#[ORM\OneToMany(mappedBy: 'relatedOrder', targetEntity: Payment::class,cascade:["persist"])]private Collection $payments;#[ORM\Column(length: 255, nullable: true,unique:true)]private ?string $reference = null;#[ORM\ManyToOne(inversedBy: 'orders',cascade:["persist"])]#[ORM\JoinColumn(name: "cash_box_order_id", referencedColumnName: "id", onDelete: "SET NULL")]private ?CashBoxOrder $cashBoxOrder = null;public function __construct(){$this->orderItems = new ArrayCollection();$this->adjustments = new ArrayCollection();$this->createdAt = new \DateTime();$this->customerWalletPoints = new ArrayCollection();$this->payments = new ArrayCollection();}public function __toString(): string{return $this->getOrderNumber();}public function getId(): ?int{return $this->id;}#[Groups(['read'])]public function getOrderNumber($secondaryPrefix=null){$prefix = "";$orderNumber = $prefix.$this->createdAt->format("ym").str_pad((string) $this->id, 5, "0", STR_PAD_LEFT);if($secondaryPrefix){$orderNumber = $prefix.$this->createdAt->format("ym").str_pad((string) $this->id, 5, "0", STR_PAD_LEFT)."-".$secondaryPrefix;}if($this->reference){return $this->reference;}return $orderNumber;}#[Groups(['read'])]public function getIdPrefixed(){return $this->getOrderNumber();}public function getCreatedAt(): ?\DateTime{return $this->createdAt;}public function setCreatedAt(?\DateTime $createdAt): self{$this->createdAt = $createdAt;return $this;}public function getCustomer(): ?Customer{return $this->customer;}public function setCustomer(?Customer $customer): self{$this->customer = $customer;return $this;}public function getCategoriesProduct(){$categories = [];foreach($this->getOrderItems() as $singleOrderItem){if($singleOrderItem->getProduct()){if($singleOrderItem->getProduct()->getParentCategory()){$categories[] = $singleOrderItem->getProduct()->getParentCategory()->getName();}}}return $categories;}public function getSubCategoriesProduct(){$categories = [];foreach($this->getOrderItems() as $singleOrderItem){if($singleOrderItem->getProduct()){foreach($singleOrderItem->getProduct()->getCategoriesProduct() as $singleCategory){if(!in_array($singleCategory->getName(),$categories)){$categories[] = $singleCategory->getName();}}}}return $categories;}/*** @return Collection|OrderItem[]*/public function getOrderItems(): Collection{return $this->orderItems;}public function addOrderItem(OrderItem $orderItem): self{if (!$this->orderItems->contains($orderItem)) {$this->orderItems[] = $orderItem;$orderItem->setParentOrder($this);}return $this;}public function removeOrderItem(OrderItem $orderItem): self{if ($this->orderItems->removeElement($orderItem)) {// set the owning side to null (unless already changed)if ($orderItem->getParentOrder() === $this) {$orderItem->setParentOrder(null);}}return $this;}/*** @return Collection|Adjustment[]*/public function getAdjustments(): Collection{return $this->adjustments;}public function addAdjustment(Adjustment $adjustment): self{if (!$this->adjustments->contains($adjustment)) {$this->adjustments[] = $adjustment;$adjustment->setParentOrder($this);}return $this;}public function removeAdjustment(Adjustment $adjustment): self{if ($this->adjustments->removeElement($adjustment)) {// set the owning side to null (unless already changed)if ($adjustment->getParentOrder() === $this) {$adjustment->setParentOrder(null);}}return $this;}public function getReductionOnCoupon(){$reductionCoupon=0;if($this->getCoupon()){if($this->getCoupon()->getTypeReduction()=="percent"){$reductionCoupon = ($this->getTotalAmount()/100)*$this->getCoupon()->getValueReduction();}else{$reductionCoupon = $this->getCoupon()->getValueReduction();}}return $reductionCoupon;}public function getFirstName(): ?string{return $this->firstName;}public function setFirstName(string $firstName): self{$this->firstName = $firstName;return $this;}public function getLastName(): ?string{return $this->lastName;}public function setLastName(string $lastName): self{$this->lastName = $lastName;return $this;}public function getCompanyName(): ?string{return $this->companyName;}public function setCompanyName(?string $companyName): self{$this->companyName = $companyName;return $this;}public function getAddress(): ?string{return $this->address;}public function setAddress(string $address): self{$this->address = $address;return $this;}public function getCity(): ?string{return $this->city;}public function setCity(string $city): self{$this->city = $city;return $this;}public function getCountry(): ?string{return $this->country;}public function setCountry(string $country): self{$this->country = $country;return $this;}public function getDepartment(): ?string{return $this->department;}public function setDepartment(?string $department): self{$this->department = $department;return $this;}public function getPostcode(): ?string{return $this->postcode;}public function setPostcode(?string $postcode): self{$this->postcode = $postcode;return $this;}public function getEmail(): ?string{return $this->email;}public function setEmail(string $email): self{$this->email = $email;return $this;}public function getTel(): ?string{return $this->tel;}public function setTel(string $tel): self{$this->tel = $tel;return $this;}public function getComment(): ?string{return $this->comment;}public function setComment(?string $comment): self{$this->comment = $comment;return $this;}#[Groups(['read'])]public function getTotalAmount(){$total=0;foreach($this->orderItems as $singleOrderItem){$total = $total + ($singleOrderItem->getTotalAmount());}return $total;}//needs optimisation#[Groups(['read'])]public function getShippingFees(){$fees = 0;if($this->getShippingMethod()){if($this->getShippingMethod()->isIsSeparatelyCalculated()){$fees = $this->getShippingMethod()->getPrice();foreach($this->getShippingMethod()->getShippingRules() as $shippingRule){if($shippingRule->getTypeCalculation() == "distance"){if( $shippingRule->getMin() < $this->getDistance() and $shippingRule->getMax() >= $this->getDistance() ){$fees = $this->getDistance() * $shippingRule->getValueCalculation();/*Condition for TLCS may be it works for all people*/if ($fees < $this->getShippingMethod()->getPrice()){$fees = $this->getShippingMethod()->getPrice();}/*Condition for TLCS may be it works for all people*/}}else{if($shippingRule->getMin() < $this->getTotalAmount() and $shippingRule->getMax() >= $this->getTotalAmount()){if($shippingRule->getTypeCalculation() == "percent"){$fees = ($this->getTotalAmount() / 100 ) * $shippingRule->getValueCalculation();}else{$fees = $shippingRule->getValueCalculation();}}}}}}return $fees;}#[Groups(['read'])]public function getTotalReduction(){$total=0;foreach($this->orderItems as $singleOrderItem){$total = $total + ($singleOrderItem->getReduction());}return $total;}public function getReductionOnTotal(){$reductionAmount = 0;if($this->getReduction() and $this->getReduction()>0){$reductionAmount = ($this->getTotalAmount() / 100) * $this->getReduction();}return $reductionAmount;}#[Groups(['read'])]public function getAmountPayedByCredit(){$total=0;foreach($this->getCustomerWalletPoints() as $singleWalletPoints){if($singleWalletPoints->getPoints()<0){$total = $total + ($singleWalletPoints->getPoints());}}return $total;}#[Groups(['read'])]public function getAmountEarnedAsCredit(){$total=0;foreach($this->getCustomerWalletPoints() as $singleWalletPoints){if($singleWalletPoints->getPoints()>0){$total = $total + ($singleWalletPoints->getPoints());}}return $total;}public function getDemandeFund(): ?DemandeFund{return $this->demandeFund;}public function setDemandeFund(?DemandeFund $demandeFund): self{$this->demandeFund = $demandeFund;return $this;}public function getStatus(): ?string{$status = "order_finance_verification_pending";if($this->status){$status = $this->status;}return $status;}public function setStatus(?string $status): self{$this->status = $status;return $this;}// BySamir : TO CLEANpublic function getSource(): ?string{return $this->source;}public function setSource(?string $source): self{$this->source = $source;return $this;}public function getDeliveryAt(){return $this->deliveryAt;}public function setDeliveryAt($deliveryAt){$this->deliveryAt = $deliveryAt;return $this;}public function getRecoveryAt(){return $this->recoveryAt;}public function setRecoveryAt($recoveryAt){$this->recoveryAt = $recoveryAt;return $this;}public function getReduction(): ?float{return $this->reduction;}public function setReduction(?float $reduction): self{$this->reduction = $reduction;return $this;}public function getShippingMethod(): ?ShippingMethod{return $this->shippingMethod;}public function setShippingMethod(?ShippingMethod $shippingMethod): self{$this->shippingMethod = $shippingMethod;return $this;}public function getAgent(): ?Agent{return $this->agent;}public function setAgent(?Agent $agent): self{$this->agent = $agent;return $this;}public function getPaymentMethod(): ?paymentMethod{return $this->paymentMethod;}public function setPaymentMethod(?paymentMethod $paymentMethod): self{$this->paymentMethod = $paymentMethod;return $this;}public function getPayedAmount(): ?float{return $this->payedAmount;}public function setPayedAmount(?float $payedAmount): self{$this->payedAmount = $payedAmount;return $this;}public function getStartProcessingAt(): ?\DateTimeInterface{return $this->startProcessingAt;}public function setStartProcessingAt(?\DateTimeInterface $startProcessingAt): self{$this->startProcessingAt = $startProcessingAt;return $this;}public function getDeliveryType(): ?string{return $this->deliveryType;}public function setDeliveryType(?string $deliveryType): self{$this->deliveryType = $deliveryType;return $this;}public function getStartDeliveryAt(): ?\DateTimeInterface{return $this->startDeliveryAt;}public function setStartDeliveryAt(?\DateTimeInterface $startDeliveryAt): self{$this->startDeliveryAt = $startDeliveryAt;return $this;}/*** @return Collection<int, CustomerWalletPoint>*/public function getCustomerWalletPoints(): Collection{return $this->customerWalletPoints;}public function addCustomerWalletPoint(CustomerWalletPoint $customerWalletPoint): self{if (!$this->customerWalletPoints->contains($customerWalletPoint)) {$this->customerWalletPoints[] = $customerWalletPoint;$customerWalletPoint->setOriginOrder($this);}return $this;}public function removeCustomerWalletPoint(CustomerWalletPoint $customerWalletPoint): self{if ($this->customerWalletPoints->removeElement($customerWalletPoint)) {// set the owning side to null (unless already changed)if ($customerWalletPoint->getOriginOrder() === $this) {$customerWalletPoint->setOriginOrder(null);}}return $this;}public function getCoupon(): ?Coupon{return $this->coupon;}public function setCoupon(?Coupon $coupon): self{$this->coupon = $coupon;return $this;}public function getAgentToDo(): ?Agent{return $this->agentToDo;}public function setAgentToDo(?Agent $agentToDo): self{$this->agentToDo = $agentToDo;return $this;}public function getIsToDo(): ?bool{return $this->isToDo;}public function setIsToDo(?bool $isToDo): self{$this->isToDo = $isToDo;return $this;}public function getCityRegionShipping(): ?CityRegion{return $this->cityRegionShipping;}public function setCityRegionShipping(?CityRegion $cityRegionShipping): self{$this->cityRegionShipping = $cityRegionShipping;return $this;}public function getVendor(): ?Vendor{return $this->vendor;}public function setVendor(?Vendor $vendor): self{$this->vendor = $vendor;return $this;}public function getCollectAddress(): ?string{return $this->collectAddress;}public function setCollectAddress(?string $collectAddress): self{$this->collectAddress = $collectAddress;return $this;}public function getCollectTel(): ?string{return $this->collectTel;}public function setCollectTel(?string $collectTel): self{$this->collectTel = $collectTel;return $this;}public function getIsHeavy(): ?bool{return $this->isHeavy;}public function setIsHeavy(?bool $isHeavy): self{$this->isHeavy = $isHeavy;return $this;}public function getShippingTips(): ?float{return $this->shippingTips;}public function setShippingTips(?float $shippingTips): self{$this->shippingTips = $shippingTips;return $this;}/*** Get the value of isChecked*/public function getIsChecked(){return $this->isChecked;}/*** Set the value of isChecked** @return self*/public function setIsChecked($isChecked){$this->isChecked = $isChecked;return $this;}/*** Get the value of walletPaymentAmount*/public function getWalletPaymentAmount(){return $this->walletPaymentAmount;}/*** Set the value of walletPaymentAmount** @return self*/public function setWalletPaymentAmount($walletPaymentAmount){$this->walletPaymentAmount = $walletPaymentAmount;return $this;}/*** Get the value of cityRegionCollect*/public function getCityRegionCollect(){return $this->cityRegionCollect;}/*** Set the value of cityRegionCollect** @return self*/public function setCityRegionCollect($cityRegionCollect){$this->cityRegionCollect = $cityRegionCollect;return $this;}/*** Get the value of distance*/public function getDistance(){return $this->distance;}/*** Set the value of distance** @return self*/public function setDistance($distance){$this->distance = $distance;return $this;}/*** Get the value of tokenStripe*/public function getTokenStripe(){return $this->tokenStripe;}/*** Set the value of tokenStripe** @return self*/public function setTokenStripe($tokenStripe){$this->tokenStripe = $tokenStripe;return $this;}public function getOrderType(): ?string{return $this->orderType;}public function setOrderType(?string $orderType): self{$this->orderType = $orderType;return $this;}/*** Get the value of deletedAt*/public function getDeletedAt(){return $this->deletedAt;}/*** Set the value of deletedAt** @return self*/public function setDeletedAt($deletedAt){$this->deletedAt = $deletedAt;return $this;}public function getStore(): ?Store{return $this->store;}public function setStore(?Store $store): self{$this->store = $store;return $this;}public function getShipment(): ?Shipment{return $this->shipment;}public function setShipment(?Shipment $shipment): self{$this->shipment = $shipment;return $this;}public function getInvoice(): ?Invoice{return $this->invoice;}public function setInvoice(?Invoice $invoice): self{$this->invoice = $invoice;return $this;}/*** Get the value of shippingAddress*/public function getShippingAddress(){return $this->shippingAddress;}/*** Set the value of shippingAddress** @return self*/public function setShippingAddress($shippingAddress){$this->shippingAddress = $shippingAddress;return $this;}public function getCreatedBy(){return $this->createdBy;}public function getDescription(): ?string{return $this->description;}public function setDescription(?string $description): self{$this->description = $description;return $this;}/*** @return Collection<int, Payment>*/public function getPayments(): Collection{return $this->payments;}public function addPayment(Payment $payment): self{if (!$this->payments->contains($payment)) {$this->payments->add($payment);$payment->setRelatedOrder($this);}return $this;}public function removePayment(Payment $payment): self{if ($this->payments->removeElement($payment)) {// set the owning side to null (unless already changed)if ($payment->getRelatedOrder() === $this) {$payment->setRelatedOrder(null);}}return $this;}public function getReference(): ?string{return $this->reference;}public function setReference(?string $reference): self{$this->reference = $reference;return $this;}public function getCashBoxOrder(): ?CashBoxOrder{return $this->cashBoxOrder;}public function setCashBoxOrder(?CashBoxOrder $cashBoxOrder): self{$this->cashBoxOrder = $cashBoxOrder;return $this;}}