<?php
namespace App\Entity\Slave;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="eposm_s_product_transfer")
* @ORM\Entity(repositoryClass="App\Repository\Slave\ProductTransferRepository")
*/
class ProductTransfer
{
public function isEditable($warehouseId){
if(
($this->getWarehouseFrom()->getId() == $warehouseId || ($this->getType() == 'destination' and $this->getWarehouseTo()->getId()))
&& ($this->getPhase() == 'inserted' || $this->getPhase() == 'product_insert' || $this->getPhase() == 'inserted_editable')
)
return true;
return false;
}
public function hasProductsTransfered(){
foreach($this->products as $jtppt){
if($jtppt->isTransferOk())
return true;
}
return false;
}
public function displayPhase($type){
switch($this->getPhase()){
case 'inserted': $color = 'color_r'; $title = 'Inserito'; break;
case 'product_insert': $color = 'color_am'; $title = 'Prodotti da inserire'; break;
case 'inserted_editable': $color = 'color_am'; $title = 'In attesa di invio'; break;
case 'waiting_receiver': $color = 'color_gr'; $title = 'In attesa di consegna'; break;
case 'to_download': $color = 'color_am'; $title = 'Da scaricare'; break;
case 'completed': $color = 'color_gr'; $title = 'Completato'; break;
default: break;
}
switch($type){
case 'icon': $html = '<i class="icon-circle cursor_p '.$color.'" data-bs-toggle="tooltip" title="'.$title.'"></i>'; break;
case 'string': $html = '<i class="icon-circle cursor_p '.$color.'"></i> '.$title; break;
default: break;
}
return $html;
}
public function displayPhaseDdt($type){
switch($this->getPhaseDdt()){
case 'create': $color = 'color_r'; $title = 'Da fare'; break;
case 'prepared': $color = 'color_am'; $title = 'Preparato'; break;
case 'signed_missing': $color = 'color_sc'; $title = 'DDT firmato mancante'; break;
case 'completed': $color = 'color_gr'; $title = 'Caricato'; break;
default: break;
}
switch($type){
case 'icon': return '<i class="icon-circle cursor_p '.$color.'" data-bs-toggle="tooltip" title="'.$title.'"></i>'; break;
case 'string': return '<i class="icon-circle cursor_p '.$color.'"></i> '.$title; break;
default: break;
}
}
public function canMakeActionsByType($action, $user, $transferWarehouseId, $transferInternalDdtActive){
$canContinue = false;
foreach($user->getWarehouses() as $jtuw){
if($jtuw->getWarehouse()->getId() == $transferWarehouseId)
$canContinue = true;
}
foreach($user->getAccountType()->getPermissions() as $jtatp){
if($jtatp->getPermission()->getSlug() == 'warehouse')
$perm = $jtatp;
}
if($canContinue || $perm->getRw() == 'RW'){
switch($this->getType()){
case 'destination': // Verso destinazione esterna -> Lo vede solo sede centrale
switch($action){
case 'resume': if($this->getPhase() == 'inserted' || $this->getPhase() == 'product_insert' || $this->getPhase() == 'inserted_editable') return true; break;
case 'prepare_ddt': if(($this->getPhase() == 'inserted' || $this->getPhase() == 'inserted_editable') && sizeof($this->getProducts()) > 0 && $this->getPhaseDdt() == 'create') return true; break;
case 'complete': if($this->getPhase() == 'waiting_receiver' && $this->getPhaseDdt() == 'prepared' && sizeof($this->getProducts()) > 0) return true; break;
default: break;
}
break;
case 'main': // Verso sede centrale
switch($action){
case 'resume': if(($this->getPhase() == 'inserted' || $this->getPhase() == 'inserted_editable')) return true; break;
case 'prepare_ddt':
if(($this->getPhase() == 'inserted' || $this->getPhase() == 'inserted_editable') && sizeof($this->getProducts()) > 0){
if($transferInternalDdtActive){
if($this->getPhaseDdt() == 'create')
return true;
}
else
return true;
}
break;
case 'complete':
if(sizeof($this->getProducts()) > 0 && $this->getPhase() == 'waiting_receiver'){
if($transferInternalDdtActive){
if($this->getPhaseDdt() == 'prepared')
return true;
}
else
return true;
}
break;
case 'download': if(sizeof($this->getProducts()) > 0 && $this->getPhase() == 'to_download' && $user->getAccountTypology() != 'technician') return true; break;
default: break;
}
break;
case 'technician': // Verso tecnico
switch($action){
case 'resume': if($this->getPhase() == 'inserted' || $this->getPhase() == 'inserted_editable') return true; break;
case 'prepare_ddt':
if(($this->getPhase() == 'inserted' || $this->getPhase() == 'inserted_editable') && sizeof($this->getProducts()) > 0){
if($transferInternalDdtActive){
if($this->getPhaseDdt() == 'create')
return true;
}
else
return true;
}
break;
case 'complete':
if(sizeof($this->getProducts()) > 0 && $this->getPhase() == 'waiting_receiver'){
if($transferInternalDdtActive){
if($this->getPhaseDdt() == 'prepared')
return true;
}
else
return true;
}
break;
case 'download': if(sizeof($this->getProducts()) > 0 && $this->getPhase() == 'to_download') return true; break;
default: break;
}
break;
default: break;
}
}
return false;
}
/**
* @ORM\Column(name="id", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="date", type="datetime", nullable=true)
*/
protected $date;
/**
* @ORM\Column(name="phase", type="string", nullable=true)
*/
protected $phase;
/**
* @ORM\Column(name="phase_ddt", type="string", nullable=true)
*/
protected $phaseDdt;
/**
* @ORM\Column(name="datetime_creation", type="datetime", nullable=true)
*/
protected $datetimeCreation;
/**
* @ORM\Column(name="datetime_send", type="datetime", nullable=true)
*/
protected $datetimeSend;
/**
* @ORM\Column(name="datetime_completion", type="datetime", nullable=true)
*/
protected $datetimeCompletion;
/**
* @ORM\Column(name="stock_order", type="string", nullable=true)
*/
protected $stockOrder;
/**
* @ORM\Column(name="ddt", type="string", nullable=true)
*/
protected $ddt;
/**
* @ORM\Column(name="ddt_path", type="string", nullable=true)
*/
protected $ddtPath;
/**
* @ORM\Column(name="signed_ddt_path", type="string", nullable=true)
*/
protected $signedDdtPath;
/**
* @ORM\Column(name="type", type="string", length=191)
*/
protected $type;
/**
* @ORM\Column(name="is_ddt_mandatory", type="boolean")
*/
protected $ddtMandatory = false;
/**
* @ORM\Column(name="is_divestment", type="boolean")
*/
protected $divestment = false;
// ManyToOne
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Slave\Warehouse", inversedBy="transfersFrom")
* @ORM\JoinColumn(name="warehouse_from_id", referencedColumnName="id")
*/
private $warehouseFrom;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Slave\Warehouse", inversedBy="transfersTo")
* @ORM\JoinColumn(name="warehouse_to_id", referencedColumnName="id")
*/
private $warehouseTo;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Slave\User", inversedBy="transfersUserFrom")
* @ORM\JoinColumn(name="user_from_id", referencedColumnName="id")
*/
private $userFrom;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Slave\User", inversedBy="transfersUserTo")
* @ORM\JoinColumn(name="user_to_id", referencedColumnName="id")
*/
private $userTo;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Slave\Supplier", inversedBy="transfers")
* @ORM\JoinColumn(name="supplier_id", referencedColumnName="id")
*/
private $supplier;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Slave\DdtHeader", inversedBy="transfers")
* @ORM\JoinColumn(name="ddt_header_id", referencedColumnName="id")
*/
private $ddtHeader;
//
// OneToMany
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\JoinTableProductProductTransfer", mappedBy="transfer")
*/
private $products;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\ProductTransferLog", mappedBy="transfer")
*/
private $logs;
public function __construct()
{
$this->products = new ArrayCollection();
$this->imports = new ArrayCollection();
$this->logs = new ArrayCollection();
}
//
public function getId(): ?string
{
return $this->id;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(?\DateTimeInterface $date): static
{
$this->date = $date;
return $this;
}
public function getPhase(): ?string
{
return $this->phase;
}
public function setPhase(?string $phase): static
{
$this->phase = $phase;
return $this;
}
public function getPhaseDdt(): ?string
{
return $this->phaseDdt;
}
public function setPhaseDdt(?string $phaseDdt): static
{
$this->phaseDdt = $phaseDdt;
return $this;
}
public function getDatetimeCreation(): ?\DateTimeInterface
{
return $this->datetimeCreation;
}
public function setDatetimeCreation(?\DateTimeInterface $datetimeCreation): static
{
$this->datetimeCreation = $datetimeCreation;
return $this;
}
public function getDatetimeSend(): ?\DateTimeInterface
{
return $this->datetimeSend;
}
public function setDatetimeSend(?\DateTimeInterface $datetimeSend): static
{
$this->datetimeSend = $datetimeSend;
return $this;
}
public function getDatetimeCompletion(): ?\DateTimeInterface
{
return $this->datetimeCompletion;
}
public function setDatetimeCompletion(?\DateTimeInterface $datetimeCompletion): static
{
$this->datetimeCompletion = $datetimeCompletion;
return $this;
}
public function getStockOrder(): ?string
{
return $this->stockOrder;
}
public function setStockOrder(?string $stockOrder): static
{
$this->stockOrder = $stockOrder;
return $this;
}
public function getDdt(): ?string
{
return $this->ddt;
}
public function setDdt(?string $ddt): static
{
$this->ddt = $ddt;
return $this;
}
public function getDdtPath(): ?string
{
return $this->ddtPath;
}
public function setDdtPath(?string $ddtPath): static
{
$this->ddtPath = $ddtPath;
return $this;
}
public function getSignedDdtPath(): ?string
{
return $this->signedDdtPath;
}
public function setSignedDdtPath(?string $signedDdtPath): static
{
$this->signedDdtPath = $signedDdtPath;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): static
{
$this->type = $type;
return $this;
}
public function isDdtMandatory(): ?bool
{
return $this->ddtMandatory;
}
public function setDdtMandatory(bool $ddtMandatory): static
{
$this->ddtMandatory = $ddtMandatory;
return $this;
}
public function isDivestment(): ?bool
{
return $this->divestment;
}
public function setDivestment(bool $divestment): static
{
$this->divestment = $divestment;
return $this;
}
public function getWarehouseFrom(): ?Warehouse
{
return $this->warehouseFrom;
}
public function setWarehouseFrom(?Warehouse $warehouseFrom): static
{
$this->warehouseFrom = $warehouseFrom;
return $this;
}
public function getWarehouseTo(): ?Warehouse
{
return $this->warehouseTo;
}
public function setWarehouseTo(?Warehouse $warehouseTo): static
{
$this->warehouseTo = $warehouseTo;
return $this;
}
public function getUserFrom(): ?User
{
return $this->userFrom;
}
public function setUserFrom(?User $userFrom): static
{
$this->userFrom = $userFrom;
return $this;
}
public function getUserTo(): ?User
{
return $this->userTo;
}
public function setUserTo(?User $userTo): static
{
$this->userTo = $userTo;
return $this;
}
public function getSupplier(): ?Supplier
{
return $this->supplier;
}
public function setSupplier(?Supplier $supplier): static
{
$this->supplier = $supplier;
return $this;
}
public function getDdtHeader(): ?DdtHeader
{
return $this->ddtHeader;
}
public function setDdtHeader(?DdtHeader $ddtHeader): static
{
$this->ddtHeader = $ddtHeader;
return $this;
}
/**
* @return Collection<int, JoinTableProductProductTransfer>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(JoinTableProductProductTransfer $product): static
{
if (!$this->products->contains($product)) {
$this->products->add($product);
$product->setTransfer($this);
}
return $this;
}
public function removeProduct(JoinTableProductProductTransfer $product): static
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getTransfer() === $this) {
$product->setTransfer(null);
}
}
return $this;
}
/**
* @return Collection<int, ProductTransferLog>
*/
public function getLogs(): Collection
{
return $this->logs;
}
public function addLog(ProductTransferLog $log): static
{
if (!$this->logs->contains($log)) {
$this->logs->add($log);
$log->setTransfer($this);
}
return $this;
}
public function removeLog(ProductTransferLog $log): static
{
if ($this->logs->removeElement($log)) {
// set the owning side to null (unless already changed)
if ($log->getTransfer() === $this) {
$log->setTransfer(null);
}
}
return $this;
}
}