src/Entity/Slave/ProductTransfer.php line 270

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Slave;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Table(name="eposm_s_product_transfer")
  9.  * @ORM\Entity(repositoryClass="App\Repository\Slave\ProductTransferRepository")
  10.  */
  11. class ProductTransfer
  12. {        
  13.     public function isEditable($warehouseId){
  14.         if(
  15.             ($this->getWarehouseFrom()->getId() == $warehouseId || ($this->getType() == 'destination' and $this->getWarehouseTo()->getId()))
  16.             && ($this->getPhase() == 'inserted' || $this->getPhase() == 'product_insert' || $this->getPhase() == 'inserted_editable')
  17.         )
  18.             return true;
  19.         return false;
  20.     }
  21.     public function hasProductsTransfered(){
  22.         foreach($this->products as $jtppt){
  23.             if($jtppt->isTransferOk())
  24.                 return true;
  25.         }
  26.         return false;
  27.     }
  28.     public function displayPhase($type){
  29.         switch($this->getPhase()){
  30.             case 'inserted'$color 'color_r'$title 'Inserito'; break;
  31.             case 'product_insert'$color 'color_am'$title 'Prodotti da inserire'; break;
  32.             case 'inserted_editable'$color 'color_am'$title 'In attesa di invio'; break;
  33.             case 'waiting_receiver'$color 'color_gr'$title 'In attesa di consegna'; break;
  34.             case 'to_download'$color 'color_am'$title 'Da scaricare'; break;
  35.             case 'in_progress'$color 'color_am'$title 'Da scaricare'; break;
  36.             case 'completed'$color 'color_gr'$title 'Completato'; break;
  37.             default: break;
  38.         }
  39.         switch($type){
  40.             case 'icon'$html '<i class="icon-circle cursor_p '.$color.'" data-bs-toggle="tooltip" title="'.$title.'"></i>'; break;
  41.             case 'string'$html '<i class="icon-circle cursor_p '.$color.'"></i> '.$title; break;
  42.             default: break;
  43.         }
  44.         return $html;
  45.     }
  46.     public function displayPhaseDdt($type){
  47.         switch($this->getPhaseDdt()){
  48.             case 'create'$color 'color_r'$title 'Da fare'; break;
  49.             case 'prepared'$color 'color_am'$title 'Preparato'; break;
  50.             case 'signed_missing'$color 'color_sc'$title 'DDT firmato mancante'; break;
  51.             case 'completed'$color 'color_gr'$title 'Caricato'; break;
  52.             default: break;
  53.         }
  54.         switch($type){
  55.             case 'icon': return '<i class="icon-circle cursor_p '.$color.'" data-bs-toggle="tooltip" title="'.$title.'"></i>'; break;
  56.             case 'string': return '<i class="icon-circle cursor_p '.$color.'"></i> '.$title; break;
  57.             default: break;
  58.         }
  59.     }
  60.     public function canMakeActionsByType($action$user$transferWarehouseId$transferInternalDdtActive){
  61.         $canContinue false;
  62.         foreach($user->getWarehouses() as $jtuw){
  63.             if($jtuw->getWarehouse()->getId() == $transferWarehouseId)
  64.                 $canContinue true;
  65.         }
  66.         foreach($user->getAccountType()->getPermissions() as $jtatp){
  67.             if($jtatp->getPermission()->getSlug() == 'warehouse')
  68.                 $perm $jtatp;
  69.         }
  70.         if($canContinue || $perm->getRw() == 'RW'){
  71.             switch($this->getType()){
  72.                 case 'destination'// Verso destinazione esterna -> Lo vede solo sede centrale
  73.                     switch($action){
  74.                         case 'resume': if($this->getPhase() == 'inserted' || $this->getPhase() == 'product_insert' || $this->getPhase() == 'inserted_editable') return true; break;
  75.                         case 'prepare_ddt': if(($this->getPhase() == 'inserted' || $this->getPhase() == 'inserted_editable') && sizeof($this->getProducts()) > && $this->getPhaseDdt() == 'create') return true; break;
  76.                         case 'complete': if($this->getPhase() == 'waiting_receiver' && $this->getPhaseDdt() == 'prepared' && sizeof($this->getProducts()) > 0) return true; break;
  77.                         default: break;
  78.                     }
  79.                     break;
  80.                 case 'main'// Verso sede centrale
  81.                     switch($action){
  82.                         case 'resume': if(($this->getPhase() == 'inserted' || $this->getPhase() == 'inserted_editable')) return true; break;
  83.                         case 'prepare_ddt'
  84.                             if(($this->getPhase() == 'inserted' || $this->getPhase() == 'inserted_editable') && sizeof($this->getProducts()) > 0){
  85.                                 if($transferInternalDdtActive){
  86.                                     if($this->getPhaseDdt() == 'create')
  87.                                         return true;
  88.                                 }
  89.                                 else
  90.                                     return true;
  91.                             }
  92.                             break;
  93.                         case 'complete'
  94.                             if(sizeof($this->getProducts()) > && $this->getPhase() == 'waiting_receiver'){
  95.                                 if($transferInternalDdtActive){
  96.                                     if($this->getPhaseDdt() == 'prepared')
  97.                                         return true;
  98.                                 }
  99.                                 else
  100.                                     return true;
  101.                             }
  102.                             break;
  103.                         case 'download': if(sizeof($this->getProducts()) > && $this->getPhase() == 'to_download' && $user->getAccountTypology() != 'technician') return true; break;
  104.                         default: break;
  105.                     }
  106.                     break;
  107.                 case 'technician'// Verso tecnico
  108.                     switch($action){
  109.                         case 'resume': if($this->getPhase() == 'inserted' || $this->getPhase() == 'inserted_editable') return true; break;
  110.                         case 'prepare_ddt'
  111.                             if(($this->getPhase() == 'inserted' || $this->getPhase() == 'inserted_editable') && sizeof($this->getProducts()) > 0){
  112.                                 if($transferInternalDdtActive){
  113.                                     if($this->getPhaseDdt() == 'create')
  114.                                         return true;
  115.                                 }
  116.                                 else
  117.                                     return true;
  118.                             }
  119.                             break;
  120.                         case 'complete'
  121.                             if(sizeof($this->getProducts()) > && $this->getPhase() == 'waiting_receiver'){
  122.                                 if($transferInternalDdtActive){
  123.                                     if($this->getPhaseDdt() == 'prepared')
  124.                                         return true;
  125.                                 }
  126.                                 else
  127.                                     return true;
  128.                             }
  129.                             break;
  130.                         case 'download': if(sizeof($this->getProducts()) > && $this->getPhase() == 'to_download') return true; break;
  131.                         default: break;
  132.                     }
  133.                     break;
  134.                 default: break;
  135.             }
  136.         }
  137.         return false;
  138.     }
  139.     /**
  140.      * @ORM\Column(name="id", type="bigint")
  141.      * @ORM\Id
  142.      * @ORM\GeneratedValue(strategy="AUTO")
  143.      */
  144.     protected $id;
  145.     /**
  146.      * @ORM\Column(name="date", type="datetime", nullable=true)
  147.      */
  148.     protected $date;
  149.     /**
  150.      * @ORM\Column(name="phase", type="string", nullable=true)
  151.      */
  152.     protected $phase;
  153.     
  154.     /**
  155.      * @ORM\Column(name="phase_ddt", type="string", nullable=true)
  156.      */
  157.     protected $phaseDdt;
  158.     /**
  159.      * @ORM\Column(name="datetime_creation", type="datetime", nullable=true)
  160.      */
  161.     protected $datetimeCreation;
  162.     
  163.     /**
  164.      * @ORM\Column(name="datetime_send", type="datetime", nullable=true)
  165.      */
  166.     protected $datetimeSend;
  167.     
  168.     /**
  169.      * @ORM\Column(name="datetime_completion", type="datetime", nullable=true)
  170.      */
  171.     protected $datetimeCompletion;
  172.     
  173.     /**
  174.      * @ORM\Column(name="stock_order", type="string", nullable=true)
  175.      */
  176.     protected $stockOrder;
  177.     
  178.     /**
  179.      * @ORM\Column(name="ddt", type="string", nullable=true)
  180.      */
  181.     protected $ddt;
  182.     
  183.     /**
  184.      * @ORM\Column(name="ddt_path", type="string", nullable=true)
  185.      */
  186.     protected $ddtPath;
  187.     
  188.     /**
  189.      * @ORM\Column(name="signed_ddt_path", type="string", nullable=true)
  190.      */
  191.     protected $signedDdtPath;
  192.     /**
  193.      * @ORM\Column(name="type", type="string", length=191)
  194.      */
  195.     protected $type;
  196.     /**
  197.      * @ORM\Column(name="is_ddt_mandatory", type="boolean")
  198.      */
  199.     protected $ddtMandatory false;
  200.     /**
  201.      * @ORM\Column(name="is_divestment", type="boolean")
  202.      */
  203.     protected $divestment false;
  204.     // ManyToOne
  205.         /**
  206.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\Warehouse", inversedBy="transfersFrom")
  207.          * @ORM\JoinColumn(name="warehouse_from_id", referencedColumnName="id")
  208.          */
  209.         private $warehouseFrom;
  210.         /**
  211.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\Warehouse", inversedBy="transfersTo")
  212.          * @ORM\JoinColumn(name="warehouse_to_id", referencedColumnName="id")
  213.          */
  214.         private $warehouseTo;
  215.         /**
  216.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\User", inversedBy="transfersUserFrom")
  217.          * @ORM\JoinColumn(name="user_from_id", referencedColumnName="id")
  218.          */
  219.         private $userFrom;
  220.         /**
  221.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\User", inversedBy="transfersUserTo")
  222.          * @ORM\JoinColumn(name="user_to_id", referencedColumnName="id")
  223.          */
  224.         private $userTo;
  225.         
  226.         /**
  227.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\Supplier", inversedBy="transfers")
  228.          * @ORM\JoinColumn(name="supplier_id", referencedColumnName="id")
  229.          */
  230.         private $supplier;
  231.         
  232.         /**
  233.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\DdtHeader", inversedBy="transfers")
  234.          * @ORM\JoinColumn(name="ddt_header_id", referencedColumnName="id")
  235.          */
  236.         private $ddtHeader;
  237.     //
  238.     // OneToMany
  239.         /**
  240.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\JoinTableProductProductTransfer", mappedBy="transfer")
  241.          */
  242.         private $products;
  243.         /**
  244.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\ProductTransferLog", mappedBy="transfer")
  245.          */
  246.         private $logs;
  247.         public function __construct()
  248.         {
  249.             $this->products = new ArrayCollection();
  250.             $this->imports = new ArrayCollection();
  251.             $this->logs = new ArrayCollection();
  252.         }
  253.         public function getId(): ?string
  254.         {
  255.             return $this->id;
  256.         }
  257.         public function getDate(): ?\DateTimeInterface
  258.         {
  259.             return $this->date;
  260.         }
  261.         public function setDate(?\DateTimeInterface $date): static
  262.         {
  263.             $this->date $date;
  264.             return $this;
  265.         }
  266.         public function getPhase(): ?string
  267.         {
  268.             return $this->phase;
  269.         }
  270.         public function setPhase(?string $phase): static
  271.         {
  272.             $this->phase $phase;
  273.             return $this;
  274.         }
  275.         public function getPhaseDdt(): ?string
  276.         {
  277.             return $this->phaseDdt;
  278.         }
  279.         public function setPhaseDdt(?string $phaseDdt): static
  280.         {
  281.             $this->phaseDdt $phaseDdt;
  282.             return $this;
  283.         }
  284.         public function getDatetimeCreation(): ?\DateTimeInterface
  285.         {
  286.             return $this->datetimeCreation;
  287.         }
  288.         public function setDatetimeCreation(?\DateTimeInterface $datetimeCreation): static
  289.         {
  290.             $this->datetimeCreation $datetimeCreation;
  291.             return $this;
  292.         }
  293.         public function getDatetimeSend(): ?\DateTimeInterface
  294.         {
  295.             return $this->datetimeSend;
  296.         }
  297.         public function setDatetimeSend(?\DateTimeInterface $datetimeSend): static
  298.         {
  299.             $this->datetimeSend $datetimeSend;
  300.             return $this;
  301.         }
  302.         public function getDatetimeCompletion(): ?\DateTimeInterface
  303.         {
  304.             return $this->datetimeCompletion;
  305.         }
  306.         public function setDatetimeCompletion(?\DateTimeInterface $datetimeCompletion): static
  307.         {
  308.             $this->datetimeCompletion $datetimeCompletion;
  309.             return $this;
  310.         }
  311.         public function getStockOrder(): ?string
  312.         {
  313.             return $this->stockOrder;
  314.         }
  315.         public function setStockOrder(?string $stockOrder): static
  316.         {
  317.             $this->stockOrder $stockOrder;
  318.             return $this;
  319.         }
  320.         public function getDdt(): ?string
  321.         {
  322.             return $this->ddt;
  323.         }
  324.         public function setDdt(?string $ddt): static
  325.         {
  326.             $this->ddt $ddt;
  327.             return $this;
  328.         }
  329.         public function getDdtPath(): ?string
  330.         {
  331.             return $this->ddtPath;
  332.         }
  333.         public function setDdtPath(?string $ddtPath): static
  334.         {
  335.             $this->ddtPath $ddtPath;
  336.             return $this;
  337.         }
  338.         public function getSignedDdtPath(): ?string
  339.         {
  340.             return $this->signedDdtPath;
  341.         }
  342.         public function setSignedDdtPath(?string $signedDdtPath): static
  343.         {
  344.             $this->signedDdtPath $signedDdtPath;
  345.             return $this;
  346.         }
  347.         public function getType(): ?string
  348.         {
  349.             return $this->type;
  350.         }
  351.         public function setType(string $type): static
  352.         {
  353.             $this->type $type;
  354.             return $this;
  355.         }
  356.         public function isDdtMandatory(): ?bool
  357.         {
  358.             return $this->ddtMandatory;
  359.         }
  360.         public function setDdtMandatory(bool $ddtMandatory): static
  361.         {
  362.             $this->ddtMandatory $ddtMandatory;
  363.             return $this;
  364.         }
  365.         public function isDivestment(): ?bool
  366.         {
  367.             return $this->divestment;
  368.         }
  369.         public function setDivestment(bool $divestment): static
  370.         {
  371.             $this->divestment $divestment;
  372.             return $this;
  373.         }
  374.         public function getWarehouseFrom(): ?Warehouse
  375.         {
  376.             return $this->warehouseFrom;
  377.         }
  378.         public function setWarehouseFrom(?Warehouse $warehouseFrom): static
  379.         {
  380.             $this->warehouseFrom $warehouseFrom;
  381.             return $this;
  382.         }
  383.         public function getWarehouseTo(): ?Warehouse
  384.         {
  385.             return $this->warehouseTo;
  386.         }
  387.         public function setWarehouseTo(?Warehouse $warehouseTo): static
  388.         {
  389.             $this->warehouseTo $warehouseTo;
  390.             return $this;
  391.         }
  392.         public function getUserFrom(): ?User
  393.         {
  394.             return $this->userFrom;
  395.         }
  396.         public function setUserFrom(?User $userFrom): static
  397.         {
  398.             $this->userFrom $userFrom;
  399.             return $this;
  400.         }
  401.         public function getUserTo(): ?User
  402.         {
  403.             return $this->userTo;
  404.         }
  405.         public function setUserTo(?User $userTo): static
  406.         {
  407.             $this->userTo $userTo;
  408.             return $this;
  409.         }
  410.         public function getSupplier(): ?Supplier
  411.         {
  412.             return $this->supplier;
  413.         }
  414.         public function setSupplier(?Supplier $supplier): static
  415.         {
  416.             $this->supplier $supplier;
  417.             return $this;
  418.         }
  419.         public function getDdtHeader(): ?DdtHeader
  420.         {
  421.             return $this->ddtHeader;
  422.         }
  423.         public function setDdtHeader(?DdtHeader $ddtHeader): static
  424.         {
  425.             $this->ddtHeader $ddtHeader;
  426.             return $this;
  427.         }
  428.         /**
  429.          * @return Collection<int, JoinTableProductProductTransfer>
  430.          */
  431.         public function getProducts(): Collection
  432.         {
  433.             return $this->products;
  434.         }
  435.         public function addProduct(JoinTableProductProductTransfer $product): static
  436.         {
  437.             if (!$this->products->contains($product)) {
  438.                 $this->products->add($product);
  439.                 $product->setTransfer($this);
  440.             }
  441.             return $this;
  442.         }
  443.         public function removeProduct(JoinTableProductProductTransfer $product): static
  444.         {
  445.             if ($this->products->removeElement($product)) {
  446.                 // set the owning side to null (unless already changed)
  447.                 if ($product->getTransfer() === $this) {
  448.                     $product->setTransfer(null);
  449.                 }
  450.             }
  451.             return $this;
  452.         }
  453.         /**
  454.          * @return Collection<int, ProductTransferLog>
  455.          */
  456.         public function getLogs(): Collection
  457.         {
  458.             return $this->logs;
  459.         }
  460.         public function addLog(ProductTransferLog $log): static
  461.         {
  462.             if (!$this->logs->contains($log)) {
  463.                 $this->logs->add($log);
  464.                 $log->setTransfer($this);
  465.             }
  466.             return $this;
  467.         }
  468.         public function removeLog(ProductTransferLog $log): static
  469.         {
  470.             if ($this->logs->removeElement($log)) {
  471.                 // set the owning side to null (unless already changed)
  472.                 if ($log->getTransfer() === $this) {
  473.                     $log->setTransfer(null);
  474.                 }
  475.             }
  476.             return $this;
  477.         }
  478. }