src/Entity/Slave/Ticket.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Slave;
  3. use App\Twig\Extension\AppExtension;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Table(name="eposm_s_ticket")
  10.  * @ORM\Entity(repositoryClass="App\Repository\Slave\TicketRepository")
  11.  */
  12. class Ticket
  13. {    
  14.     public function canDelete($type){
  15.         switch($type){
  16.             case 'all':
  17.                 if(sizeof($this->getSuspensions()) > 0) return false;
  18.                 if(sizeof($this->getInterventions()) > 0) return false;
  19.                 break;
  20.             case 'activities':
  21.                 foreach($this->getInterventions() as $intervention){
  22.                     if($intervention->getOutcomeType()->getSlug() == 'comleted')
  23.                         return false;
  24.                 }
  25.                 break;
  26.         }
  27.         return true;
  28.     }
  29.     
  30.     public function canMakeActionByStatus($statusesSlug){
  31.         $array = array();
  32.         if(str_contains($statusesSlug','))
  33.             $array explode(','$statusesSlug);
  34.         else
  35.             array_push($array$statusesSlug);
  36.         if(in_array($this->getStatus()->getSlug(), $array))
  37.             return true;
  38.         return false;
  39.     }
  40.     public function displayStatus($type)
  41.     {
  42.         if($this->isSystemError()){
  43.             $color 'color_r';
  44.             $title 'Con errori';
  45.         }
  46.         else{
  47.             switch($this->getStatus()->getSlug()){
  48.                 case 'to_assign'$color 'color_lb'; break;
  49.                 case 'assigned'$color 'color_am'; break;
  50.                 case 'taken_charge'$color 'color_gr'; break;
  51.                 case 'suspension_request'$color 'color_am'; break;
  52.                 case 'suspended'$color 'color_r'; break;
  53.                 case 'closed'$color 'color_gr'; break;
  54.                 case 'closed_portal'$color 'color_gr_dark'; break;
  55.                 case 'canceled'$color 'color_r'; break;
  56.                 case 'wrong'$color 'color_r'; break;
  57.                 case 'temp'$color 'color_r'; break;
  58.                 default: break;
  59.             }
  60.             $title $this->getStatus()->getValue();
  61.         }
  62.         switch($type){
  63.             case 'icon': return '<i class="icon-circle cursor_p '.$color.'" data-bs-toggle="tooltip" title="'.$title.'"></i>'; break;
  64.             case 'string': return '<i class="icon-circle cursor_p '.$color.'"></i> '.$title; break;
  65.         }
  66.     }
  67.     public function displayJsonReport()
  68.     {
  69.         $html '';
  70.         if($this->jsonReport != '[]'){
  71.             $matrix json_decode($this->jsonReporttrue);
  72.             foreach($matrix as $array)
  73.                 foreach($array as $a)
  74.                     $html.= '<tr><th>'.array_keys($array)[0].'</th><td colspan="2">'.$a.'</td></tr>';
  75.         }
  76.         return $html;
  77.     }
  78.     public function displayTableJson()
  79.     {
  80.         $html '';
  81.         $first true;
  82.         $matrix json_decode($this->jsontrue);
  83.         $html.= '<table class="table table_no_padding m_b_none b_none font_12">';
  84.         foreach($matrix as $array)
  85.             foreach($array as $a)
  86.                 $html.= '<tr><th>'.array_keys($array)[0].'</th><td>'.$a.'</td></tr>';
  87.         
  88.         $html.= '</table>';
  89.         return $html;
  90.     }
  91.     public function displayJsonValueByColumn($column){
  92.         $matrix json_decode($this->jsontrue);
  93.         foreach($matrix as $array)
  94.             foreach($array as $a)
  95.                 if(strtolower(array_keys($array)[0]) == strtolower($column))
  96.                     return $a;
  97.         return '';
  98.     }
  99.     
  100.     public function displayJsonReportValueByColumn($column){
  101.         $matrix json_decode($this->jsonReporttrue);
  102.         foreach($matrix as $array)
  103.             foreach($array as $a)
  104.                 if(strtolower(array_keys($array)[0]) == strtolower($column))
  105.                     return $a;
  106.         return '';
  107.     }
  108.     
  109.     public function displayNumberAndOperation()
  110.     {
  111.         return 'Numero: '.$this->getNumber().' --- Cliente: '.$this->getClient().' --- Operazione: '.$this->getOperation()->getValue();
  112.     }
  113.     public function getActualSuspension()
  114.     {
  115.         $now = new \Datetime();
  116.         foreach($this->getSuspensions() as $suspension){
  117.             if($suspension->getDatetimeFrom()->format('YmdHis') <= $now->format('YmdHis') && !$suspension->isUnlocked()){
  118.                 return $suspension;
  119.             }
  120.         }
  121.         return null;
  122.     }
  123.     public function getLastSuspension()
  124.     {
  125.         $returnSus null;
  126.         $array = array();
  127.         foreach($this->getSuspensions() as $suspension){
  128.             if($suspension->isManaged() && $suspension->isApproved()){
  129.                 // SE LA DATA E' INDETERMINATA E' PER FORZA L'ULTIMA SOSPENSIONE, ALTRIMENTI AVREBBE UNA DATA DI SCADENZA
  130.                 if($suspension->getDatetimeTo() == null)
  131.                     return $suspension;
  132.                 array_push($array$suspension);
  133.             }
  134.         }
  135.         $first true;
  136.         foreach($array as $sus){
  137.             if($first || $returnSus->getDatetimeTo()->format('YmdHis') <= $sus->getDatetimeTo()->format('YmdHis')){
  138.                 $returnSus $sus;
  139.                 $first false;
  140.             }
  141.         }
  142.         return $returnSus;
  143.     }
  144.     
  145.     public function getInterventionCompleted()
  146.     {
  147.         foreach($this->getInterventions() as $intervention){
  148.             if($intervention->getOutcomeType()->getSlug() == 'completed'){
  149.                 return $intervention;
  150.             }
  151.         }
  152.         return null;
  153.     }
  154.     public function getOpenSuspension()
  155.     {
  156.         foreach($this->getSuspensions() as $sus){
  157.             if($sus->getDatetimeTo() == null && $sus->getRefuseMotivation() == 'Sospeso dal fornitore')
  158.                 return $sus;
  159.         }
  160.     }
  161.     /**
  162.      * @ORM\Column(name="id", type="bigint")
  163.      * @ORM\Id
  164.      * @ORM\GeneratedValue(strategy="AUTO")
  165.      */
  166.     protected $id;
  167.     
  168.     /**
  169.      * @ORM\Column(name="number", type="string", length=191, nullable=true)
  170.      */
  171.     protected $number;
  172.     /**
  173.      * @ORM\Column(name="datetime_import", type="datetime", nullable=true)
  174.      */
  175.     protected $datetimeImport;
  176.     /**
  177.      * @ORM\Column(name="datetime_start", type="datetime", nullable=true)
  178.      */
  179.     protected $datetimeStart;
  180.     /**
  181.      * @ORM\Column(name="datetime_expiration", type="datetime", nullable=true)
  182.      */
  183.     protected $datetimeExpiration;
  184.     /**
  185.      * @ORM\Column(name="datetime_end", type="datetime", nullable=true)
  186.      */
  187.     protected $datetimeEnd;
  188.     /**
  189.      * @ORM\Column(name="address", type="string", length=191, nullable=true)
  190.      */
  191.     protected $address;
  192.     /**
  193.      * @ORM\Column(name="locality", type="string", length=191, nullable=true)
  194.      */
  195.     protected $locality;
  196.     /**
  197.      * @ORM\Column(name="zip", type="string", length=191, nullable=true)
  198.      */
  199.     protected $zip;
  200.     /**
  201.      * @ORM\Column(name="id_city", type="bigint", nullable=true)
  202.      */
  203.     protected $idCity;
  204.     /**
  205.      * @ORM\Column(name="id_province", type="bigint", nullable=true)
  206.      */
  207.     protected $idProvince;
  208.     
  209.     /**
  210.      * @ORM\Column(name="other_city", type="string", length=191, nullable=true)
  211.      */
  212.     protected $otherCity;
  213.     /**
  214.      * @ORM\Column(name="system_error", type="boolean")
  215.      */
  216.     protected $systemError false;
  217.     
  218.     /**
  219.      * @ORM\Column(name="system_error_slug", type="string", length=191, nullable=true)
  220.      */
  221.     protected $systemErrorSlug;
  222.     /**
  223.      * @ORM\Column(name="system_error_details", type="text", nullable=true)
  224.      */
  225.     protected $systemErrorDetails;
  226.     
  227.     /**
  228.      * @ORM\Column(name="json", type="text", nullable=true)
  229.      */
  230.     protected $json;
  231.     
  232.     /**
  233.      * @ORM\Column(name="directory_path", type="string", length=191)
  234.      */
  235.     protected $directoryPath;
  236.     /**
  237.      * @ORM\Column(name="waybill", type="string", length=191, nullable=true)
  238.      */
  239.     protected $waybill;
  240.     
  241.     /**
  242.      * @ORM\Column(name="json_report", type="text", nullable=true)
  243.      */
  244.     protected $jsonReport '[]';
  245.     
  246.     /**
  247.      * @ORM\Column(name="billable", type="boolean")
  248.      */
  249.     protected $billable true;
  250.     /**
  251.      * @ORM\Column(name="closed_on_portal", type="boolean")
  252.      */
  253.     protected $closedOnPortal false;
  254.     // ManyToOne
  255.         /**
  256.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\Supplier", inversedBy="tickets")
  257.          * @ORM\JoinColumn(name="supplier_id", referencedColumnName="id")
  258.          */
  259.         private $supplier;
  260.         /**
  261.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\Client", inversedBy="tickets")
  262.          * @ORM\JoinColumn(name="client_id", referencedColumnName="id")
  263.          */
  264.         private $client;
  265.         /**
  266.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\Operation", inversedBy="tickets")
  267.          * @ORM\JoinColumn(name="operation_id", referencedColumnName="id")
  268.          */
  269.         private $operation;
  270.         /**
  271.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\User", inversedBy="tickets")
  272.          * @ORM\JoinColumn(name="technician_id", referencedColumnName="id")
  273.          */
  274.         private $technician;
  275.         /**
  276.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\TicketStatus", inversedBy="tickets")
  277.          * @ORM\JoinColumn(name="status_id", referencedColumnName="id")
  278.          */
  279.         private $status;
  280.         
  281.         /**
  282.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\Termid", inversedBy="tickets")
  283.          * @ORM\JoinColumn(name="termid_id", referencedColumnName="id")
  284.          */
  285.         private $termid;
  286.         
  287.         /**
  288.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\OperationTariffAmount", inversedBy="tickets")
  289.          * @ORM\JoinColumn(name="operation_tariff_amount_id", referencedColumnName="id")
  290.          */
  291.         private $operationTariffAmount;
  292.                 
  293.         /**
  294.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\OperationTariffAmount", inversedBy="uavTickets")
  295.          * @ORM\JoinColumn(name="uav_operation_tariff_amount_id", referencedColumnName="id")
  296.          */
  297.         private $uavOperationTariffAmount;
  298.     //
  299.     // OneToMany
  300.         /**
  301.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\TicketSuspension", mappedBy="ticket")
  302.          */
  303.         private $suspensions;
  304.         /**
  305.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\Intervention", mappedBy="ticket")
  306.          */
  307.         private $interventions;
  308.         
  309.         /**
  310.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\TicketReminder", mappedBy="ticket")
  311.          */
  312.         private $reminders;
  313.         public function __construct()
  314.         {
  315.             $this->suspensions = new ArrayCollection();
  316.             $this->interventions = new ArrayCollection();
  317.             $this->reminders = new ArrayCollection();
  318.         }
  319.     //
  320.     public function getId(): ?string
  321.     {
  322.         return $this->id;
  323.     }
  324.     public function getNumber(): ?string
  325.     {
  326.         return $this->number;
  327.     }
  328.     public function setNumber(?string $number): static
  329.     {
  330.         $this->number $number;
  331.         return $this;
  332.     }
  333.     public function getDatetimeImport(): ?\DateTimeInterface
  334.     {
  335.         return $this->datetimeImport;
  336.     }
  337.     public function setDatetimeImport(?\DateTimeInterface $datetimeImport): static
  338.     {
  339.         $this->datetimeImport $datetimeImport;
  340.         return $this;
  341.     }
  342.     public function getDatetimeStart(): ?\DateTimeInterface
  343.     {
  344.         return $this->datetimeStart;
  345.     }
  346.     public function setDatetimeStart(?\DateTimeInterface $datetimeStart): static
  347.     {
  348.         $this->datetimeStart $datetimeStart;
  349.         return $this;
  350.     }
  351.     public function getDatetimeExpiration(): ?\DateTimeInterface
  352.     {
  353.         return $this->datetimeExpiration;
  354.     }
  355.     public function setDatetimeExpiration(?\DateTimeInterface $datetimeExpiration): static
  356.     {
  357.         $this->datetimeExpiration $datetimeExpiration;
  358.         return $this;
  359.     }
  360.     public function getDatetimeEnd(): ?\DateTimeInterface
  361.     {
  362.         return $this->datetimeEnd;
  363.     }
  364.     public function setDatetimeEnd(?\DateTimeInterface $datetimeEnd): static
  365.     {
  366.         $this->datetimeEnd $datetimeEnd;
  367.         return $this;
  368.     }
  369.     public function getAddress(): ?string
  370.     {
  371.         return $this->address;
  372.     }
  373.     public function setAddress(?string $address): static
  374.     {
  375.         $this->address $address;
  376.         return $this;
  377.     }
  378.     public function getLocality(): ?string
  379.     {
  380.         return $this->locality;
  381.     }
  382.     public function setLocality(?string $locality): static
  383.     {
  384.         $this->locality $locality;
  385.         return $this;
  386.     }
  387.     public function getZip(): ?string
  388.     {
  389.         return $this->zip;
  390.     }
  391.     public function setZip(?string $zip): static
  392.     {
  393.         $this->zip $zip;
  394.         return $this;
  395.     }
  396.     public function getIdCity(): ?string
  397.     {
  398.         return $this->idCity;
  399.     }
  400.     public function setIdCity(?string $idCity): static
  401.     {
  402.         $this->idCity $idCity;
  403.         return $this;
  404.     }
  405.     public function getIdProvince(): ?string
  406.     {
  407.         return $this->idProvince;
  408.     }
  409.     public function setIdProvince(?string $idProvince): static
  410.     {
  411.         $this->idProvince $idProvince;
  412.         return $this;
  413.     }
  414.     public function getOtherCity(): ?string
  415.     {
  416.         return $this->otherCity;
  417.     }
  418.     public function setOtherCity(?string $otherCity): static
  419.     {
  420.         $this->otherCity $otherCity;
  421.         return $this;
  422.     }
  423.     public function isSystemError(): ?bool
  424.     {
  425.         return $this->systemError;
  426.     }
  427.     public function setSystemError(bool $systemError): static
  428.     {
  429.         $this->systemError $systemError;
  430.         return $this;
  431.     }
  432.     public function getSystemErrorSlug(): ?string
  433.     {
  434.         return $this->systemErrorSlug;
  435.     }
  436.     public function setSystemErrorSlug(?string $systemErrorSlug): static
  437.     {
  438.         $this->systemErrorSlug $systemErrorSlug;
  439.         return $this;
  440.     }
  441.     public function getSystemErrorDetails(): ?string
  442.     {
  443.         return $this->systemErrorDetails;
  444.     }
  445.     public function setSystemErrorDetails(?string $systemErrorDetails): static
  446.     {
  447.         $this->systemErrorDetails $systemErrorDetails;
  448.         return $this;
  449.     }
  450.     public function getJson(): ?string
  451.     {
  452.         return $this->json;
  453.     }
  454.     public function setJson(?string $json): static
  455.     {
  456.         $this->json $json;
  457.         return $this;
  458.     }
  459.     public function getDirectoryPath(): ?string
  460.     {
  461.         return $this->directoryPath;
  462.     }
  463.     public function setDirectoryPath(string $directoryPath): static
  464.     {
  465.         $this->directoryPath $directoryPath;
  466.         return $this;
  467.     }
  468.     public function getJsonReport(): ?string
  469.     {
  470.         return $this->jsonReport;
  471.     }
  472.     public function setJsonReport(?string $jsonReport): static
  473.     {
  474.         $this->jsonReport $jsonReport;
  475.         return $this;
  476.     }
  477.     public function isBillable(): ?bool
  478.     {
  479.         return $this->billable;
  480.     }
  481.     public function setBillable(bool $billable): static
  482.     {
  483.         $this->billable $billable;
  484.         return $this;
  485.     }
  486.     public function isClosedOnPortal(): ?bool
  487.     {
  488.         return $this->closedOnPortal;
  489.     }
  490.     public function setClosedOnPortal(bool $closedOnPortal): static
  491.     {
  492.         $this->closedOnPortal $closedOnPortal;
  493.         return $this;
  494.     }
  495.     public function getSupplier(): ?Supplier
  496.     {
  497.         return $this->supplier;
  498.     }
  499.     public function setSupplier(?Supplier $supplier): static
  500.     {
  501.         $this->supplier $supplier;
  502.         return $this;
  503.     }
  504.     public function getClient(): ?Client
  505.     {
  506.         return $this->client;
  507.     }
  508.     public function setClient(?Client $client): static
  509.     {
  510.         $this->client $client;
  511.         return $this;
  512.     }
  513.     public function getOperation(): ?Operation
  514.     {
  515.         return $this->operation;
  516.     }
  517.     public function setOperation(?Operation $operation): static
  518.     {
  519.         $this->operation $operation;
  520.         return $this;
  521.     }
  522.     public function getTechnician(): ?User
  523.     {
  524.         return $this->technician;
  525.     }
  526.     public function setTechnician(?User $technician): static
  527.     {
  528.         $this->technician $technician;
  529.         return $this;
  530.     }
  531.     public function getStatus(): ?TicketStatus
  532.     {
  533.         return $this->status;
  534.     }
  535.     public function setStatus(?TicketStatus $status): static
  536.     {
  537.         $this->status $status;
  538.         return $this;
  539.     }
  540.     public function getTermid(): ?Termid
  541.     {
  542.         return $this->termid;
  543.     }
  544.     public function setTermid(?Termid $termid): static
  545.     {
  546.         $this->termid $termid;
  547.         return $this;
  548.     }
  549.     public function getOperationTariffAmount(): ?OperationTariffAmount
  550.     {
  551.         return $this->operationTariffAmount;
  552.     }
  553.     public function setOperationTariffAmount(?OperationTariffAmount $operationTariffAmount): static
  554.     {
  555.         $this->operationTariffAmount $operationTariffAmount;
  556.         return $this;
  557.     }
  558.     public function getUavOperationTariffAmount(): ?OperationTariffAmount
  559.     {
  560.         return $this->uavOperationTariffAmount;
  561.     }
  562.     public function setUavOperationTariffAmount(?OperationTariffAmount $uavOperationTariffAmount): static
  563.     {
  564.         $this->uavOperationTariffAmount $uavOperationTariffAmount;
  565.         return $this;
  566.     }
  567.     /**
  568.      * @return Collection<int, TicketSuspension>
  569.      */
  570.     public function getSuspensions(): Collection
  571.     {
  572.         return $this->suspensions;
  573.     }
  574.     public function addSuspension(TicketSuspension $suspension): static
  575.     {
  576.         if (!$this->suspensions->contains($suspension)) {
  577.             $this->suspensions->add($suspension);
  578.             $suspension->setTicket($this);
  579.         }
  580.         return $this;
  581.     }
  582.     public function removeSuspension(TicketSuspension $suspension): static
  583.     {
  584.         if ($this->suspensions->removeElement($suspension)) {
  585.             // set the owning side to null (unless already changed)
  586.             if ($suspension->getTicket() === $this) {
  587.                 $suspension->setTicket(null);
  588.             }
  589.         }
  590.         return $this;
  591.     }
  592.     /**
  593.      * @return Collection<int, Intervention>
  594.      */
  595.     public function getInterventions(): Collection
  596.     {
  597.         return $this->interventions;
  598.     }
  599.     public function addIntervention(Intervention $intervention): static
  600.     {
  601.         if (!$this->interventions->contains($intervention)) {
  602.             $this->interventions->add($intervention);
  603.             $intervention->setTicket($this);
  604.         }
  605.         return $this;
  606.     }
  607.     public function removeIntervention(Intervention $intervention): static
  608.     {
  609.         if ($this->interventions->removeElement($intervention)) {
  610.             // set the owning side to null (unless already changed)
  611.             if ($intervention->getTicket() === $this) {
  612.                 $intervention->setTicket(null);
  613.             }
  614.         }
  615.         return $this;
  616.     }
  617.     /**
  618.      * @return Collection<int, TicketReminder>
  619.      */
  620.     public function getReminders(): Collection
  621.     {
  622.         return $this->reminders;
  623.     }
  624.     public function addReminder(TicketReminder $reminder): static
  625.     {
  626.         if (!$this->reminders->contains($reminder)) {
  627.             $this->reminders->add($reminder);
  628.             $reminder->setTicket($this);
  629.         }
  630.         return $this;
  631.     }
  632.     public function removeReminder(TicketReminder $reminder): static
  633.     {
  634.         if ($this->reminders->removeElement($reminder)) {
  635.             // set the owning side to null (unless already changed)
  636.             if ($reminder->getTicket() === $this) {
  637.                 $reminder->setTicket(null);
  638.             }
  639.         }
  640.         return $this;
  641.     }
  642.     public function getWaybill(): ?string
  643.     {
  644.         return $this->waybill;
  645.     }
  646.     public function setWaybill(?string $waybill): static
  647.     {
  648.         $this->waybill $waybill;
  649.         return $this;
  650.     }
  651. }