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