src/Entity/Slave/Ticket.php line 20

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(
  10.  *     name="eposm_s_ticket",
  11.  *     uniqueConstraints={
  12.  *         @ORM\UniqueConstraint(columns={"number", "termid_id"})
  13.  *     }
  14.  * )
  15.  * @ORM\Entity(repositoryClass="App\Repository\Slave\TicketRepository")
  16.  */
  17. class Ticket
  18. {    
  19.     public function canDelete($type){
  20.         switch($type){
  21.             case 'all':
  22.                 if(sizeof($this->getSuspensions()) > 0) return false;
  23.                 if(sizeof($this->getInterventions()) > 0) return false;
  24.                 break;
  25.             case 'activities':
  26.                 foreach($this->getInterventions() as $intervention){
  27.                     if($intervention->getOutcomeType()->getSlug() == 'comleted')
  28.                         return false;
  29.                 }
  30.                 break;
  31.         }
  32.         return true;
  33.     }
  34.     
  35.     public function canMakeActionByStatus($statusesSlug){
  36.         $array = array();
  37.         if(str_contains($statusesSlug','))
  38.             $array explode(','$statusesSlug);
  39.         else
  40.             array_push($array$statusesSlug);
  41.         if(in_array($this->getStatus()->getSlug(), $array))
  42.             return true;
  43.         return false;
  44.     }
  45.     public function displayStatus($type)
  46.     {
  47.         if($this->isSystemError()){
  48.             $color 'color_r';
  49.             $title 'Con errori';
  50.         }
  51.         else{
  52.             switch($this->getStatus()->getSlug()){
  53.                 case 'to_assign'$color 'color_lb'; break;
  54.                 case 'assigned'$color 'color_am'; break;
  55.                 case 'taken_charge'$color 'color_gr'; break;
  56.                 case 'suspension_request'$color 'color_am'; break;
  57.                 case 'suspended'$color 'color_r'; break;
  58.                 case 'closed'$color 'color_gr'; break;
  59.                 case 'closed_portal'$color 'color_gr_dark'; break;
  60.                 case 'canceled'$color 'color_r'; break;
  61.                 case 'wrong'$color 'color_r'; break;
  62.                 case 'temp'$color 'color_r'; break;
  63.                 default: break;
  64.             }
  65.             $title $this->getStatus()->getValue();
  66.             if($this->getStatus()->getSlug() == 'taken_charge' && $this->isProcessed()){
  67.                 $color 'color_gr_dark';
  68.                 $title $this->getStatus()->getValue().' - Processato';
  69.             }
  70.         }
  71.         switch($type){
  72.             case 'icon': return '<i class="icon-circle cursor_p '.$color.'" data-bs-toggle="tooltip" title="'.$title.'"></i>'; break;
  73.             case 'string': return '<i class="icon-circle cursor_p '.$color.'"></i> '.$title; break;
  74.         }
  75.     }
  76.     public function displayJsonReport()
  77.     {
  78.         $html '';
  79.         if($this->jsonReport != '[]'){
  80.             $matrix json_decode($this->jsonReporttrue);
  81.             foreach($matrix as $array)
  82.                 foreach($array as $a)
  83.                     $html.= '<tr><th>'.array_keys($array)[0].'</th><td colspan="2">'.$a.'</td></tr>';
  84.         }
  85.         return $html;
  86.     }
  87.     public function displayTableJson()
  88.     {
  89.         $html '';
  90.         $first true;
  91.         $matrix json_decode($this->jsontrue);
  92.         $html.= '<table class="table table_no_padding m_b_none b_none font_12">';
  93.         foreach($matrix as $array)
  94.             foreach($array as $a)
  95.                 $html.= '<tr><th>'.array_keys($array)[0].'</th><td>'.$a.'</td></tr>';
  96.         
  97.         $html.= '</table>';
  98.         return $html;
  99.     }
  100.     public function displayJsonValueByColumn($column){
  101.         $matrix json_decode($this->jsontrue);
  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 displayJsonReportValueByColumn($column){
  110.         $matrix json_decode($this->jsonReporttrue);
  111.         foreach($matrix as $array)
  112.             foreach($array as $a)
  113.                 if(strtolower(array_keys($array)[0]) == strtolower($column))
  114.                     return $a;
  115.         return '';
  116.     }
  117.     
  118.     public function displayNumberAndOperation()
  119.     {
  120.         return 'Numero: '.$this->getNumber().' --- Cliente: '.$this->getClient().' --- Operazione: '.$this->getOperation()->getValue();
  121.     }
  122.     public function getActualSuspension()
  123.     {
  124.         $now = new \Datetime();
  125.         foreach($this->getSuspensions() as $suspension){
  126.             if($suspension->getDatetimeFrom()->format('YmdHis') <= $now->format('YmdHis') && !$suspension->isUnlocked()){
  127.                 return $suspension;
  128.             }
  129.         }
  130.         return null;
  131.     }
  132.     public function getLastSuspension()
  133.     {
  134.         $returnSus null;
  135.         $array = array();
  136.         foreach($this->getSuspensions() as $suspension){
  137.             if($suspension->isManaged() && $suspension->isApproved()){
  138.                 // SE LA DATA E' INDETERMINATA E' PER FORZA L'ULTIMA SOSPENSIONE, ALTRIMENTI AVREBBE UNA DATA DI SCADENZA
  139.                 if($suspension->getDatetimeTo() == null)
  140.                     return $suspension;
  141.                 array_push($array$suspension);
  142.             }
  143.         }
  144.         $first true;
  145.         foreach($array as $sus){
  146.             if($first || $returnSus->getDatetimeTo()->format('YmdHis') <= $sus->getDatetimeTo()->format('YmdHis')){
  147.                 $returnSus $sus;
  148.                 $first false;
  149.             }
  150.         }
  151.         return $returnSus;
  152.     }
  153.     
  154.     public function getInterventionCompleted()
  155.     {
  156.         foreach($this->getInterventions() as $intervention){
  157.             if($intervention->getOutcomeType()->getSlug() == 'completed'){
  158.                 return $intervention;
  159.             }
  160.         }
  161.         return null;
  162.     }
  163.     public function getOpenSuspension()
  164.     {
  165.         foreach($this->getSuspensions() as $sus){
  166.             if($sus->getDatetimeTo() == null && $sus->getRefuseMotivation() == 'Sospeso dal fornitore')
  167.                 return $sus;
  168.         }
  169.     }
  170.     /**
  171.      * @ORM\Column(name="id", type="bigint")
  172.      * @ORM\Id
  173.      * @ORM\GeneratedValue(strategy="AUTO")
  174.      */
  175.     protected $id;
  176.     
  177.     /**
  178.      * @ORM\Column(name="number", type="string", length=191, nullable=true)
  179.      */
  180.     protected $number;
  181.     /**
  182.      * @ORM\Column(name="datetime_import", type="datetime", nullable=true)
  183.      */
  184.     protected $datetimeImport;
  185.     /**
  186.      * @ORM\Column(name="datetime_start", type="datetime", nullable=true)
  187.      */
  188.     protected $datetimeStart;
  189.     /**
  190.      * @ORM\Column(name="datetime_expiration", type="datetime", nullable=true)
  191.      */
  192.     protected $datetimeExpiration;
  193.     /**
  194.      * @ORM\Column(name="datetime_end", type="datetime", nullable=true)
  195.      */
  196.     protected $datetimeEnd;
  197.     /**
  198.      * @ORM\Column(name="address", type="string", length=191, nullable=true)
  199.      */
  200.     protected $address;
  201.     /**
  202.      * @ORM\Column(name="locality", type="string", length=191, nullable=true)
  203.      */
  204.     protected $locality;
  205.     /**
  206.      * @ORM\Column(name="zip", type="string", length=191, nullable=true)
  207.      */
  208.     protected $zip;
  209.     /**
  210.      * @ORM\Column(name="id_city", type="bigint", nullable=true)
  211.      */
  212.     protected $idCity;
  213.     /**
  214.      * @ORM\Column(name="id_province", type="bigint", nullable=true)
  215.      */
  216.     protected $idProvince;
  217.     
  218.     /**
  219.      * @ORM\Column(name="other_city", type="string", length=191, nullable=true)
  220.      */
  221.     protected $otherCity;
  222.     /**
  223.      * @ORM\Column(name="system_error", type="boolean")
  224.      */
  225.     protected $systemError false;
  226.     
  227.     /**
  228.      * @ORM\Column(name="system_error_slug", type="string", length=191, nullable=true)
  229.      */
  230.     protected $systemErrorSlug;
  231.     /**
  232.      * @ORM\Column(name="system_error_details", type="text", nullable=true)
  233.      */
  234.     protected $systemErrorDetails;
  235.     
  236.     /**
  237.      * @ORM\Column(name="json", type="text", nullable=true)
  238.      */
  239.     protected $json;
  240.     
  241.     /**
  242.      * @ORM\Column(name="directory_path", type="string", length=191)
  243.      */
  244.     protected $directoryPath;
  245.     /**
  246.      * @ORM\Column(name="waybill", type="string", length=191, nullable=true)
  247.      */
  248.     protected $waybill;
  249.     
  250.     /**
  251.      * @ORM\Column(name="billable", type="boolean")
  252.      */
  253.     protected $billable true;
  254.     
  255.     /**
  256.      * @ORM\Column(name="json_report", type="text", nullable=true)
  257.      */
  258.     protected $jsonReport '[]';
  259.     
  260.     /**
  261.      * @ORM\Column(name="report_printed", type="boolean")
  262.      */
  263.     protected $reportPrinted false;
  264.     
  265.     /**
  266.      * @ORM\Column(name="processed", type="boolean")
  267.      */
  268.     protected $processed false;
  269.     /**
  270.      * @ORM\Column(name="closed_on_portal", type="boolean")
  271.      */
  272.     protected $closedOnPortal false;
  273.     // ManyToOne
  274.         /**
  275.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\Supplier", inversedBy="tickets")
  276.          * @ORM\JoinColumn(name="supplier_id", referencedColumnName="id")
  277.          */
  278.         private $supplier;
  279.         /**
  280.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\Client", inversedBy="tickets")
  281.          * @ORM\JoinColumn(name="client_id", referencedColumnName="id")
  282.          */
  283.         private $client;
  284.         /**
  285.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\Operation", inversedBy="tickets")
  286.          * @ORM\JoinColumn(name="operation_id", referencedColumnName="id")
  287.          */
  288.         private $operation;
  289.         /**
  290.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\User", inversedBy="tickets")
  291.          * @ORM\JoinColumn(name="technician_id", referencedColumnName="id")
  292.          */
  293.         private $technician;
  294.         /**
  295.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\TicketStatus", inversedBy="tickets")
  296.          * @ORM\JoinColumn(name="status_id", referencedColumnName="id")
  297.          */
  298.         private $status;
  299.         
  300.         /**
  301.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\Termid", inversedBy="tickets")
  302.          * @ORM\JoinColumn(name="termid_id", referencedColumnName="id")
  303.          */
  304.         private $termid;
  305.         
  306.         /**
  307.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\OperationTariffAmount", inversedBy="tickets")
  308.          * @ORM\JoinColumn(name="operation_tariff_amount_id", referencedColumnName="id")
  309.          */
  310.         private $operationTariffAmount;
  311.                 
  312.         /**
  313.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\OperationTariffAmount", inversedBy="uavTickets")
  314.          * @ORM\JoinColumn(name="uav_operation_tariff_amount_id", referencedColumnName="id")
  315.          */
  316.         private $uavOperationTariffAmount;
  317.     //
  318.     // OneToMany
  319.         /**
  320.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\TicketSuspension", mappedBy="ticket")
  321.          */
  322.         private $suspensions;
  323.         /**
  324.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\Intervention", mappedBy="ticket")
  325.          */
  326.         private $interventions;
  327.         
  328.         /**
  329.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\TicketReminder", mappedBy="ticket")
  330.          */
  331.         private $reminders;
  332.         public function __construct()
  333.         {
  334.             $this->suspensions = new ArrayCollection();
  335.             $this->interventions = new ArrayCollection();
  336.             $this->reminders = new ArrayCollection();
  337.         }
  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. }