<?php
namespace App\Entity;
use App\Repository\OrderRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=OrderRepository::class)
* @ORM\Table(name="`order`")
*/
class Order
{
const INIT = '0';
const BUDGETED = '1';
const IN_BASKET = '2';
const IN_PREPARATION = '3';
const ON_DELIVERY = '4';
const COMPLETED = '5';
const DECLINED = '6';
const REQUESTED = '7';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"order"})
*/
private $id;
/**
* @ORM\Column(type="integer")
* @Assert\NotBlank
* @Groups({"order"})
*/
private $units;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"order"})
*/
private $observations;
/**
* 0: Iniciada : El usuario ha solicitado un presupuesto al proveedor
* 1: Presupuestada : El proveedor acepta las condiciones del cliente y formula el presupuesto
* 2: En cesta : El usuario acepta el presupuesto (también el administrador puede hacerlo)
* 3: En preparación : El administrador acepta el presupuesto (o el usuario si no requiere confirmación del administrador)
* 4: En entrega : El proveedor ha fabricado y enviado las piezas
* 5: Completada : El usaurio ha recibido y comprobado las piezas y la documentación solicitada
* 6: Rechazada : Rechazada por usuario proveedor, usuario o administrador
* 7: Solicitada : El Cliente ha solicitado una orden
*
* @ORM\Column(type="integer")
* @Groups({"order"})
*/
private $state = false;
/**
* @ORM\ManyToOne(targetEntity=Company::class)
* @ORM\JoinColumn(nullable=false)
*/
private $company;
/**
* @ORM\ManyToOne(targetEntity=Supplier::class)
* @ORM\JoinColumn(nullable=false)
*/
private $supplier;
/**
* @ORM\ManyToOne(targetEntity=User::class)
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @ORM\Column(type="datetime")
* @Groups({"order"})
*/
private $created_at;
/**
* @ORM\Column(type="datetime")
* @Groups({"order"})
*/
private $updated_at;
/**
* @ORM\ManyToOne(targetEntity=Part::class, inversedBy="orders", cascade={"persist"})
* @ORM\JoinColumn(nullable=true)
* @Groups({"part"})
*/
private $part;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"order"})
*/
private $completed_at;
/**
* @ORM\Column(type="string", length=100)
* @Groups({"order"})
*/
private $type;
/**
* @ORM\Column(type="string", length=15)
* @Groups({"order"})
*/
private $ref;
/**
* @ORM\Column(type="string", length=100, nullable=true)
* @Groups({"order"})
*/
private $code;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"order"})
*/
private $observations_supplier;
/**
* @ORM\Column(type="text", nullable=true)
* @Groups({"order"})
*/
private $files_supplier;
/**
* @ORM\OneToMany(targetEntity=OrderMachineData::class, mappedBy="orderId")
*/
private $orderMachineData;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*/
private $reject_user;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $reject_date;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $budget;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $payment_terms;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $budget_valid_until;
/**
* @ORM\Column(type="string", length=100, nullable=true)
*/
private $delivery_in;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $files_budget;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*/
private $approve_user_user;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*/
private $approve_chief_user;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $approve_user_date;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $approve_chief_date;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*/
private $send_user;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $send_date;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*/
private $complete_user;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $complete_date;
/**
* @ORM\Column(type="string", length=15, nullable=true)
*/
private $accept_ref;
/**
* @ORM\OneToMany(targetEntity=OrderMessage::class, mappedBy="order_")
*/
private $orderMessages;
/**
* @ORM\ManyToOne(targetEntity=User::class)
*/
private $approve_supplier_user;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $approve_supplier_date;
/**
* Requiere doble confirmación (confirmación del administrador (ROLE_CHIEF))
*
*
* @ORM\Column(type="boolean")
*/
private $chief_confirm;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $payment_terms_id;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $budget_date;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $approve_date;
/**
* @ORM\ManyToOne(targetEntity=CompanyAddress::class)
* @ORM\JoinColumn(onDelete="SET NULL")
*/
private $shipping_address;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $budget_required;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $units_decrypted;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $units_decrypted_date;
/**
* @ORM\Column(type="text", length=255, nullable=true)
*/
private $prototypeName;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $files_order;
public function __construct()
{
$this->created_at = new \DateTime();
$this->markAsAproved();
$this->orderMachineData = new ArrayCollection();
$this->orderMessages = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getUnits(): ?int
{
return $this->units;
}
public function setUnits(int $units): self
{
$this->units = $units;
return $this;
}
public function getObservations(): ?string
{
return $this->observations;
}
public function setObservations(?string $observations): self
{
$this->observations = $observations;
return $this;
}
public function getState(): ?int
{
return $this->state;
}
public function setState(int $state): self
{
$this->state = $state;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getSupplier(): ?Supplier
{
return $this->supplier;
}
public function setSupplier(?Supplier $supplier): self
{
$this->supplier = $supplier;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
/**
* Set the value of updatedAt
*
* @param \DateTime $updatedAt
*/
public function markAsAproved() : void
{
$this->updated_at = new \DateTime();
}
/**
* Set the value of completedAt
*
* @param \DateTime $completedAt
*/
public function markAsCompleted() : void
{
$this->completed_at = new \DateTime();
}
public function getPart(): ?Part
{
return $this->part;
}
public function setPart(?Part $part): self
{
$this->part = $part;
return $this;
}
public function getCompletedAt(): ?\DateTimeInterface
{
return $this->completed_at;
}
public function setCompletedAt(?\DateTimeInterface $completed_at): self
{
$this->completed_at = $completed_at;
return $this;
}
public function getRef(): ?string
{
return $this->ref;
}
public function setRef(string $ref): self
{
$splits = explode("-", $ref);
$today = date("ymd");
if ($splits[1] == $today)
{
$splits[2]++;
$splits[2] = str_pad( $splits[2], 3, "0", STR_PAD_LEFT);
$ref = implode("-", $splits);
}else
{
$ref = $splits[0] . "-" . date("ymd") . "-001";
}
$this->ref = $ref;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(?string $code): self
{
$this->code = $code;
return $this;
}
public function getObservationsSupplier(): ?string
{
return $this->observations_supplier;
}
public function setObservationsSupplier(?string $observations_supplier): self
{
$this->observations_supplier = $observations_supplier;
return $this;
}
public function getFilesSupplier(): ?string
{
return $this->files_supplier;
}
public function setFilesSupplier(?string $files_supplier): self
{
$this->files_supplier = $files_supplier;
return $this;
}
/**
* @return Collection<int, OrderMachineData>
*/
public function getOrderMachineData(): Collection
{
return $this->orderMachineData;
}
public function addOrderMachineData(OrderMachineData $orderMachineData): self
{
if (!$this->orderMachineData->contains($orderMachineData)) {
$this->orderMachineData[] = $orderMachineData;
$orderMachineData->setOrderId($this);
}
return $this;
}
public function removeOrderMachineData(OrderMachineData $orderMachineData): self
{
if ($this->orderMachineData->removeElement($orderMachineData)) {
// set the owning side to null (unless already changed)
if ($orderMachineData->getOrderId() === $this) {
$orderMachineData->setOrderId(null);
}
}
return $this;
}
public function getRejectUser(): ?User
{
return $this->reject_user;
}
public function setRejectUser(?User $reject_user): self
{
$this->reject_user = $reject_user;
return $this;
}
public function getRejectDate(): ?\DateTimeInterface
{
return $this->reject_date;
}
public function setRejectDate(?\DateTimeInterface $reject_date): self
{
$this->reject_date = $reject_date;
return $this;
}
public function getBudget(): ?float
{
return $this->budget;
}
public function setBudget(?float $budget): self
{
$this->budget = $budget;
return $this;
}
public function getPaymentTerms(): ?string
{
return $this->payment_terms;
}
public function setPaymentTerms(?string $payment_terms): self
{
$this->payment_terms = $payment_terms;
return $this;
}
public function getBudgetValidUntil(): ?string
{
return $this->budget_valid_until;
}
public function setBudgetValidUntil(?string $budget_valid_until): self
{
$this->budget_valid_until = $budget_valid_until;
return $this;
}
public function getDeliveryIn(): ?string
{
return $this->delivery_in;
}
public function setDeliveryIn(?string $delivery_in): self
{
$this->delivery_in = $delivery_in;
return $this;
}
public function getFilesBudget(): ?string
{
return $this->files_budget;
}
public function setFilesBudget(?string $files_budget): self
{
$this->files_budget = $files_budget;
return $this;
}
public function getApproveUserUser(): ?User
{
return $this->approve_user_user;
}
public function setApproveUserUser(?User $approve_user_user): self
{
$this->approve_user_user = $approve_user_user;
return $this;
}
public function getApproveChiefUser(): ?User
{
return $this->approve_chief_user;
}
public function setApproveChiefUser(?User $approve_chief_user): self
{
$this->approve_chief_user = $approve_chief_user;
return $this;
}
public function getApproveUserDate(): ?\DateTimeInterface
{
return $this->approve_user_date;
}
public function setApproveUserDate(?\DateTimeInterface $approve_user_date): self
{
$this->approve_user_date = $approve_user_date;
return $this;
}
public function getApproveChiefDate(): ?\DateTimeInterface
{
return $this->approve_chief_date;
}
public function setApproveChiefDate(?\DateTimeInterface $approve_chief_date): self
{
$this->approve_chief_date = $approve_chief_date;
return $this;
}
public function getSendUser(): ?User
{
return $this->send_user;
}
public function setSendUser(?User $send_user): self
{
$this->send_user = $send_user;
return $this;
}
public function getSendDate(): ?\DateTimeInterface
{
return $this->send_date;
}
public function setSendDate(?\DateTimeInterface $send_date): self
{
$this->send_date = $send_date;
return $this;
}
public function getCompleteUser(): ?User
{
return $this->complete_user;
}
public function setCompleteUser(?User $complete_user): self
{
$this->complete_user = $complete_user;
return $this;
}
public function getCompleteDate(): ?\DateTimeInterface
{
return $this->complete_date;
}
public function setCompleteDate(?\DateTimeInterface $complete_date): self
{
$this->complete_date = $complete_date;
return $this;
}
public function getAcceptRef(): ?string
{
return $this->accept_ref;
}
public function setAcceptRef(?string $accept_ref): self
{
$this->accept_ref = $accept_ref;
return $this;
}
/**
* @return Collection<int, OrderMessage>
*/
public function getOrderMessages(): Collection
{
return $this->orderMessages;
}
public function addOrderMessage(OrderMessage $orderMessage): self
{
if (!$this->orderMessages->contains($orderMessage)) {
$this->orderMessages[] = $orderMessage;
$orderMessage->setOrder($this);
}
return $this;
}
public function removeOrderMessage(OrderMessage $orderMessage): self
{
if ($this->orderMessages->removeElement($orderMessage)) {
// set the owning side to null (unless already changed)
if ($orderMessage->getOrder() === $this) {
$orderMessage->setOrder(null);
}
}
return $this;
}
public function getApproveSupplierUser(): ?User
{
return $this->approve_supplier_user;
}
public function setApproveSupplierUser(?User $approve_supplier_user): self
{
$this->approve_supplier_user = $approve_supplier_user;
return $this;
}
public function getApproveSupplierDate(): ?\DateTimeInterface
{
return $this->approve_supplier_date;
}
public function setApproveSupplierDate(?\DateTimeInterface $approve_supplier_date): self
{
$this->approve_supplier_date = $approve_supplier_date;
return $this;
}
public function getChiefConfirm(): ?bool
{
return $this->chief_confirm;
}
public function setChiefConfirm(bool $chief_confirm): self
{
$this->chief_confirm = $chief_confirm;
return $this;
}
public function getPaymentTermsId(): ?int
{
return $this->payment_terms_id;
}
public function setPaymentTermsId(?int $payment_terms_id): self
{
$this->payment_terms_id = $payment_terms_id;
return $this;
}
public function getBudgetDate(): ?\DateTimeInterface
{
return $this->budget_date;
}
public function setBudgetDate(?\DateTimeInterface $budget_date): self
{
$this->budget_date = $budget_date;
return $this;
}
public function getApproveDate(): ?\DateTimeInterface
{
return $this->approve_date;
}
public function setApproveDate(?\DateTimeInterface $approve_date): self
{
$this->approve_date = $approve_date;
return $this;
}
public function getShippingAddress(): ?CompanyAddress
{
return $this->shipping_address;
}
public function setShippingAddress(?CompanyAddress $shipping_address): self
{
$this->shipping_address = $shipping_address;
return $this;
}
public function getBudgetRequired(): ?bool
{
return $this->budget_required;
}
public function setBudgetRequired(?bool $budget_required): self
{
$this->budget_required = $budget_required;
return $this;
}
public function getUnitsDecrypted(): ?int
{
return $this->units_decrypted;
}
public function setUnitsDecrypted(?int $units_decrypted): self
{
$this->units_decrypted = $units_decrypted;
return $this;
}
public function getUnitsDecryptedDate(): ?\DateTimeInterface
{
return $this->units_decrypted_date;
}
public function setUnitsDecryptedDate(?\DateTimeInterface $units_decrypted_date): self
{
$this->units_decrypted_date = $units_decrypted_date;
return $this;
}
/**
* @return mixed
*/
public function getType()
{
return $this->type;
}
/**
* @param mixed $type
*/
public function setType($type): void
{
$this->type = $type;
}
/**
* @return mixed
*/
public function getFilesOrder(): ?string
{
return $this->files_order;
}
/**
* @param mixed $files_order
*/
public function setFilesOrder(?string $files_order): self
{
$this->files_order = $files_order;
return $this;
}
/**
* @return mixed
*/
public function getPrototypeName()
{
return $this->prototypeName;
}
/**
* @param mixed $prototypeName
*/
public function setPrototypeName($prototypeName): void
{
$this->prototypeName = $prototypeName;
}
}