src/Flexy/ShopBundle/Entity/Shipping/Shipment.php line 21
<?php
namespace App\Flexy\ShopBundle\Entity\Shipping;
use ApiPlatform\Core\Annotation\ApiResource;
use App\Entity\LogHistory;
use App\Flexy\ShopBundle\Entity\Customer\Customer;
use App\Flexy\ShopBundle\Entity\Store\Store;
use App\Flexy\ShopBundle\Repository\Shipping\ShipmentRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use App\Flexy\ShopBundle\Entity\Order\Order;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Gedmo\Mapping\Annotation as Gedmo;
#[ApiResource]
#[ORM\Entity(repositoryClass: ShipmentRepository::class)]
#[Gedmo\Loggable(logEntryClass:LogHistory::class)]
class Shipment
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'datetime_immutable', nullable: true)]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Assert\NotNull]
#[Assert\NotBlank]
#[Assert\Regex(pattern: '/[a-zA-Z0-9,.]/', message: 'Address must be alphanumeric')]
private $collectAddress;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $collectAddressIndication;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $collectLng;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $collectLat;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $collectAddressPhone;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Assert\NotNull]
#[Assert\NotBlank]
#[Assert\Regex(pattern: '/[a-zA-Z0-9,.]/', message: 'Address must be alphanumeric')]
private $shippingAddress;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $shippingAddressIndication;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $shippingLng;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $shippingLat;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $shippingPhone;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $collectDate = null;
#[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $collectTime = null;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $shippingDate = null;
#[ORM\Column(type: Types::TIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $shippingTime = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $state = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $trackingCode = null;
#[ORM\Column(type: 'text', nullable: true)]
#[Gedmo\Versioned]
private ?string $description = null;
#[ORM\ManyToOne(targetEntity: ShippingMethod::class, inversedBy: 'shippments')]
private ?\App\Flexy\ShopBundle\Entity\Shipping\ShippingMethod $method = null;
#[ORM\OneToMany(targetEntity: ShipmentItem::class, mappedBy: 'shipment', orphanRemoval: true,cascade:["persist"])]
#[Assert\Count(
min: 1,
max: 5,
minMessage: 'You must specify at least one shipment item',
maxMessage: 'You cannot specify more than {{ limit }} shipment items',
groups: ['shipment-item-steps-form']
)]
private \Doctrine\Common\Collections\Collection|array $shipmentItems;
#[ORM\OneToMany(mappedBy: 'shipment', targetEntity: TrackingStep::class, orphanRemoval: true)]
private Collection $trackingSteps;
#[ORM\Column(length: 255, nullable: true)]
private ?string $status = null;
#[ORM\ManyToOne]
private ?City $collectCity = null;
#[ORM\ManyToOne]
private ?City $shippingCity = null;
#[ORM\Column(length: 255,unique:true)]
private ?string $reference = null;
#[ORM\Column(length: 255)]
#[Gedmo\Versioned]
private ?string $paymentType = null;
#[ORM\ManyToOne(inversedBy: 'sentShipments')]
#[Gedmo\Versioned]
private ?Customer $senderCustomer = null;
#[ORM\ManyToOne(inversedBy: 'receivedShipments')]
#[Gedmo\Versioned]
private ?Customer $recipientCustomer = null;
#[ORM\Column(nullable: true)]
private ?float $declaredValue = null;
#[ORM\Column(nullable: true)]
private ?float $volume = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $shippingLocationType = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $image = null;
#[ORM\OneToMany(mappedBy: 'shipment', targetEntity: CashOnDelivery::class, orphanRemoval: true,cascade:["persist"])]
#[Assert\Count(
min: 0,
max: 3,
minMessage: 'You must specify at least one COD',
maxMessage: 'You cannot specify more than {{ limit }} COD\'s ',
groups: ['cod-steps-form']
)]
private Collection $cashOnDeliveries;
#[ORM\Column(nullable: true)]
private ?float $shippingFees = null;
#[ORM\ManyToOne(inversedBy: 'collectedShipments')]
private ?Store $collectedByStore = null;
#[ORM\ManyToOne(inversedBy: 'shippedShipments')]
private ?Store $shippedByStore = null;
#[ORM\ManyToOne]
private ?ShippingMethod $shippingMethod = null;
#[ORM\OneToMany(mappedBy: 'shipment', targetEntity: ShipmentPaper::class,cascade:["persist"])]
private Collection $shipmentPapers;
#[ORM\OneToMany(mappedBy: 'shipment', targetEntity: ShipmentCollectMoney::class,cascade:["persist"])]
#[Assert\Count(
min: 1,
max: 2,
minMessage: 'You must specify at least one Shiment Collect Money',
maxMessage: 'You cannot specify more than {{ limit }} Shiment Collect Money',
groups: ['collect-money-steps-form']
)]
private Collection $shipmentCollectMoney;
#[ORM\Column(nullable: true)]
private ?bool $isCODCashCollected = null;
#[ORM\Column(nullable: true)]
private ?bool $isShipmentCollectMoneyCollected = null;
#[ORM\Column(nullable: true)]
private ?bool $isShipmentReceiptCollected = null;
#[ORM\Column(nullable: true)]
private ?bool $isCODCheckOrBillCollected = null;
#[ORM\Column(nullable: true)]
private ?bool $isDeliveryReceiptCollected = null;
#[ORM\Column(nullable: true)]
private ?bool $isInvoiceCollected = null;
#[ORM\OneToOne(mappedBy: 'shipment', cascade: ['persist'])]
private ?Order $relatedOrder = null;
#[ORM\ManyToOne(inversedBy: 'collectedShipments')]
private ?CityRegion $collectCityRegion = null;
#[ORM\ManyToOne(inversedBy: 'shippedShipments')]
private ?CityRegion $shippingCityRegion = null;
public function __toString()
{
return (string)$this->reference;
}
public function __construct()
{
$this->shipmentItems = new ArrayCollection();
$this->trackingSteps = new ArrayCollection();
$this->cashOnDeliveries = new ArrayCollection();
$this->shipmentPapers = new ArrayCollection();
$this->shipmentCollectMoney = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getState(): ?string
{
return $this->state;
}
public function setState(string $state): self
{
$this->state = $state;
return $this;
}
public function getTrackingCode(): ?string
{
return $this->trackingCode;
}
public function setTrackingCode(?string $trackingCode): self
{
$this->trackingCode = $trackingCode;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getMethod(): ?ShippingMethod
{
return $this->method;
}
public function setMethod(?ShippingMethod $method): self
{
$this->method = $method;
return $this;
}
/**
* @return Collection|ShipmentItem[]
*/
public function getShipmentItems(): Collection
{
return $this->shipmentItems;
}
public function addShipmentItem(ShipmentItem $shipmentItem): self
{
if (!$this->shipmentItems->contains($shipmentItem)) {
$this->shipmentItems[] = $shipmentItem;
$shipmentItem->setShipment($this);
}
return $this;
}
public function removeShipmentItem(ShipmentItem $shipmentItem): self
{
if ($this->shipmentItems->removeElement($shipmentItem)) {
// set the owning side to null (unless already changed)
if ($shipmentItem->getShipment() === $this) {
$shipmentItem->setShipment(null);
}
}
return $this;
}
/**
* @return Collection<int, TrackingStep>
*/
public function getTrackingSteps(): Collection
{
return $this->trackingSteps;
}
public function addTrackingStep(TrackingStep $shipmentTrackingStep): self
{
if (!$this->trackingSteps->contains($shipmentTrackingStep)) {
$this->trackingSteps->add($shipmentTrackingStep);
$shipmentTrackingStep->setShipment($this);
}
return $this;
}
public function removeTrackingStep(TrackingStep $shipmentTrackingStep): self
{
if ($this->trackingSteps->removeElement($shipmentTrackingStep)) {
// set the owning side to null (unless already changed)
if ($shipmentTrackingStep->getShipment() === $this) {
$shipmentTrackingStep->setShipment(null);
}
}
return $this;
}
public function getShipmentItemsChildren(){
$children = [];
foreach($this->getShipmentItems() as $singleItem){
foreach($singleItem->getShipmentItemChildren() as $singleChild){
$children[]= $singleChild;
}
}
return $children;
}
public function getCurrentStepTrackedChildren(){
$children = [];
foreach($this->getShipmentItems() as $singleItem){
foreach($singleItem->getShipmentItemChildren() as $singleChild){
if($singleChild->getTrackingSteps()->contains($this->getTrackingSteps()->last()) ){
$children[]= $singleChild;
}
}
}
return $children;
}
public function getAllTrackedChildren(){
$children = [];
foreach($this->getShipmentItems() as $singleItem){
foreach($singleItem->getShipmentItemChildren() as $singleChild){
$children[]= $singleChild;
}
}
return $children;
}
public function getDirectionHub(){
$direction = "";
if(count($this->getTrackingSteps()) > 0){
$direction = $this->getTrackingSteps()->last()->getStepType()->getDirectionHub();
}
return $direction;
}
public function getCurrentStep(){
$stepType = null;
if(count($this->getTrackingSteps()) > 0){
$stepType = $this->getTrackingSteps()->last()->getStepType();
}
return $stepType;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(?string $status): self
{
$this->status = $status;
return $this;
}
public function getCollectCity(): ?City
{
return $this->collectCity;
}
public function setCollectCity(?City $collectCity): self
{
$this->collectCity = $collectCity;
return $this;
}
public function getShippingCity(): ?City
{
return $this->shippingCity;
}
public function setShippingCity(?City $shippingCity): self
{
$this->shippingCity = $shippingCity;
return $this;
}
public function getReference(): ?string
{
return $this->reference;
}
public function setReference(string $reference): self
{
$this->reference = $reference;
return $this;
}
public function getPaymentType(): ?string
{
return $this->paymentType;
}
public function setPaymentType(string $paymentType): self
{
$this->paymentType = $paymentType;
return $this;
}
public function getSenderCustomer(): ?Customer
{
return $this->senderCustomer;
}
public function setSenderCustomer(?Customer $senderCustomer): self
{
$this->senderCustomer = $senderCustomer;
return $this;
}
public function getRecipientCustomer(): ?Customer
{
return $this->recipientCustomer;
}
public function setRecipientCustomer(?Customer $recipientCustomer): self
{
$this->recipientCustomer = $recipientCustomer;
return $this;
}
public function getDeclaredValue(): ?float
{
return $this->declaredValue;
}
public function setDeclaredValue(?float $declaredValue): self
{
$this->declaredValue = $declaredValue;
return $this;
}
public function getVolume(): ?float
{
return $this->volume;
}
public function setVolume(?float $volume): self
{
$this->volume = $volume;
return $this;
}
public function getShippingLocationType(): ?string
{
return $this->shippingLocationType;
}
public function setShippingLocationType(?string $shippingLocationType): self
{
$this->shippingLocationType = $shippingLocationType;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
/**
* @return Collection<int, CashOnDelivery>
*/
public function getCashOnDeliveries(): Collection
{
return $this->cashOnDeliveries;
}
public function addCashOnDelivery(CashOnDelivery $cashOnDelivery): self
{
if (!$this->cashOnDeliveries->contains($cashOnDelivery)) {
$this->cashOnDeliveries->add($cashOnDelivery);
$cashOnDelivery->setShipment($this);
}
return $this;
}
public function removeCashOnDelivery(CashOnDelivery $cashOnDelivery): self
{
if ($this->cashOnDeliveries->removeElement($cashOnDelivery)) {
// set the owning side to null (unless already changed)
if ($cashOnDelivery->getShipment() === $this) {
$cashOnDelivery->setShipment(null);
}
}
return $this;
}
public function getShippingFees(): ?float
{
return $this->shippingFees;
}
public function setShippingFees(?float $shippingFees): self
{
$this->shippingFees = $shippingFees;
return $this;
}
public function getCollectedByStore(): ?Store
{
return $this->collectedByStore;
}
public function setCollectedByStore(?Store $collectedByStore): self
{
$this->collectedByStore = $collectedByStore;
return $this;
}
public function getShippedByStore(): ?Store
{
return $this->shippedByStore;
}
public function setShippedByStore(?Store $shippedByStore): self
{
$this->shippedByStore = $shippedByStore;
return $this;
}
public function getShippingMethod(): ?ShippingMethod
{
return $this->shippingMethod;
}
public function setShippingMethod(?ShippingMethod $shippingMethod): self
{
$this->shippingMethod = $shippingMethod;
return $this;
}
/**
* @return Collection<int, ShipmentPaper>
*/
public function getShipmentPapers(): Collection
{
return $this->shipmentPapers;
}
public function addShipmentPaper(ShipmentPaper $shipmentPaper): self
{
if (!$this->shipmentPapers->contains($shipmentPaper)) {
$this->shipmentPapers->add($shipmentPaper);
$shipmentPaper->setShipment($this);
}
return $this;
}
public function removeShipmentPaper(ShipmentPaper $shipmentPaper): self
{
if ($this->shipmentPapers->removeElement($shipmentPaper)) {
// set the owning side to null (unless already changed)
if ($shipmentPaper->getShipment() === $this) {
$shipmentPaper->setShipment(null);
}
}
return $this;
}
/**
* @return Collection<int, ShipmentCollectMoney>
*/
public function getShipmentCollectMoney(): Collection
{
return $this->shipmentCollectMoney;
}
public function addShipmentCollectMoney(ShipmentCollectMoney $shipmentCollectMoney): self
{
if (!$this->shipmentCollectMoney->contains($shipmentCollectMoney)) {
$this->shipmentCollectMoney->add($shipmentCollectMoney);
$shipmentCollectMoney->setShipment($this);
}
return $this;
}
public function removeShipmentCollectMoney(ShipmentCollectMoney $shipmentCollectMoney): self
{
if ($this->shipmentCollectMoney->removeElement($shipmentCollectMoney)) {
// set the owning side to null (unless already changed)
if ($shipmentCollectMoney->getShipment() === $this) {
$shipmentCollectMoney->setShipment(null);
}
}
return $this;
}
public function isIsCODCashCollected(): ?bool
{
return $this->isCODCashCollected;
}
public function setIsCODCashCollected(?bool $isCODCashCollected): self
{
$this->isCODCashCollected = $isCODCashCollected;
return $this;
}
public function isIsShipmentCollectMoneyCollected(): ?bool
{
return $this->isShipmentCollectMoneyCollected;
}
public function setIsShipmentCollectMoneyCollected(?bool $isShipmentCollectMoneyCollected): self
{
$this->isShipmentCollectMoneyCollected = $isShipmentCollectMoneyCollected;
return $this;
}
public function isIsShipmentReceiptCollected(): ?bool
{
return $this->isShipmentReceiptCollected;
}
public function setIsShipmentReceiptCollected(?bool $isShipmentReceiptCollected): self
{
$this->isShipmentReceiptCollected = $isShipmentReceiptCollected;
return $this;
}
public function isIsCODCheckOrBillCollected(): ?bool
{
return $this->isCODCheckOrBillCollected;
}
public function setIsCODCheckOrBillCollected(?bool $isCODCheckOrBillCollected): self
{
$this->isCODCheckOrBillCollected = $isCODCheckOrBillCollected;
return $this;
}
public function isIsDeliveryReceiptCollected(): ?bool
{
return $this->isDeliveryReceiptCollected;
}
public function setIsDeliveryReceiptCollected(?bool $isDeliveryReceiptCollected): self
{
$this->isDeliveryReceiptCollected = $isDeliveryReceiptCollected;
return $this;
}
public function isIsInvoiceCollected(): ?bool
{
return $this->isInvoiceCollected;
}
public function setIsInvoiceCollected(?bool $isInvoiceCollected): self
{
$this->isInvoiceCollected = $isInvoiceCollected;
return $this;
}
public function getRelatedOrder(): ?Order
{
return $this->relatedOrder;
}
public function setRelatedOrder(?Order $relatedOrder): self
{
// unset the owning side of the relation if necessary
if ($relatedOrder === null && $this->relatedOrder !== null) {
$this->relatedOrder->setShipment(null);
}
// set the owning side of the relation if necessary
if ($relatedOrder !== null && $relatedOrder->getShipment() !== $this) {
$relatedOrder->setShipment($this);
}
$this->relatedOrder = $relatedOrder;
return $this;
}
public function getCollectCityRegion(): ?CityRegion
{
return $this->collectCityRegion;
}
public function setCollectCityRegion(?CityRegion $collectCityRegion): self
{
$this->collectCityRegion = $collectCityRegion;
return $this;
}
public function getShippingCityRegion(): ?CityRegion
{
return $this->shippingCityRegion;
}
public function setShippingCityRegion(?CityRegion $shippingCityRegion): self
{
$this->shippingCityRegion = $shippingCityRegion;
return $this;
}
public function getCollectAddress(): ?string
{
return $this->collectAddress;
}
public function setCollectAddress(?string $collectAddress): self
{
$this->collectAddress = $collectAddress;
return $this;
}
public function getCollectAddressIndication(): ?string
{
return $this->collectAddressIndication;
}
public function setCollectAddressIndication(?string $collectAddressIndication): self
{
$this->collectAddressIndication = $collectAddressIndication;
return $this;
}
public function getCollectLng(): ?string
{
return $this->collectLng;
}
public function setCollectLng(?string $collectLng): self
{
$this->collectLng = $collectLng;
return $this;
}
public function getCollectLat(): ?string
{
return $this->collectLat;
}
public function setCollectLat(?string $collectLat): self
{
$this->collectLat = $collectLat;
return $this;
}
public function getCollectAddressPhone(): ?string
{
return $this->collectAddressPhone;
}
public function setCollectAddressPhone(?string $collectAddressPhone): self
{
$this->collectAddressPhone = $collectAddressPhone;
return $this;
}
public function getShippingAddress(): ?string
{
return $this->shippingAddress;
}
public function setShippingAddress(?string $shippingAddress): self
{
$this->shippingAddress = $shippingAddress;
return $this;
}
public function getShippingAddressIndication(): ?string
{
return $this->shippingAddressIndication;
}
public function setShippingAddressIndication(?string $shippingAddressIndication): self
{
$this->shippingAddressIndication = $shippingAddressIndication;
return $this;
}
public function getShippingLng(): ?string
{
return $this->shippingLng;
}
public function setShippingLng(?string $shippingLng): self
{
$this->shippingLng = $shippingLng;
return $this;
}
public function getShippingLat(): ?string
{
return $this->shippingLat;
}
public function setShippingLat(?string $shippingLat): self
{
$this->shippingLat = $shippingLat;
return $this;
}
public function getShippingPhone(): ?string
{
return $this->shippingPhone;
}
public function setShippingPhone(?string $shippingPhone): self
{
$this->shippingPhone = $shippingPhone;
return $this;
}
/**
* Get the value of shippingTime
*/
public function getShippingTime()
{
return $this->shippingTime;
}
/**
* Set the value of shippingTime
*
* @return self
*/
public function setShippingTime($shippingTime)
{
$this->shippingTime = $shippingTime;
return $this;
}
/**
* Get the value of shippingDate
*/
public function getShippingDate()
{
return $this->shippingDate;
}
/**
* Set the value of shippingDate
*
* @return self
*/
public function setShippingDate($shippingDate)
{
$this->shippingDate = $shippingDate;
return $this;
}
/**
* Get the value of collectTime
*/
public function getCollectTime()
{
return $this->collectTime;
}
/**
* Set the value of collectTime
*
* @return self
*/
public function setCollectTime($collectTime)
{
$this->collectTime = $collectTime;
return $this;
}
/**
* Get the value of collectDate
*/
public function getCollectDate()
{
return $this->collectDate;
}
/**
* Set the value of collectDate
*
* @return self
*/
public function setCollectDate($collectDate)
{
$this->collectDate = $collectDate;
return $this;
}
}