src/Entity/MarketRumor.php line 129

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity;
  4. use ApiPlatform\Core\Annotation\ApiFilter;
  5. use ApiPlatform\Core\Annotation\ApiProperty;
  6. use ApiPlatform\Core\Annotation\ApiResource;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  9. use App\Trait\TimestampableEntity;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. use Symfony\Component\Serializer\Annotation\Groups;
  15. use Symfony\Component\Serializer\Annotation\MaxDepth;
  16. use Ramsey\Uuid\Uuid;
  17. use Ramsey\Uuid\UuidInterface;
  18. #[ORM\Entity]
  19. #[ApiResource(
  20.     iri'MarketRumor',
  21.     itemOperations: [
  22.         'get' => [
  23.             'security' => "
  24.                 is_granted('ROLE_ADMIN') or 
  25.                 is_granted('ROLE_OPERATOR') or
  26.                 is_granted('ROLE_OPERATIONS_COORDINATOR') or 
  27.                 is_granted('ROLE_RESEARCH_ANALYST') or
  28.                 is_granted('ROLE_BROKER') or 
  29.                 is_granted('ROLE_INTERN')
  30.             ",
  31.             'normalization_context' => [
  32.                 'groups' => 'market_rumor:item:get'
  33.                 'enable_max_depth' => true
  34.             ]
  35.         ],
  36.         'put' => [
  37.             'security' => "
  38.                 is_granted('ROLE_ADMIN') or 
  39.                 is_granted('ROLE_INTERN') or 
  40.                 is_granted('ROLE_RESEARCH_ANALYST') or 
  41.                 is_granted('ROLE_BROKER')
  42.             ",
  43.             'normalization_context' => [
  44.                 'groups' => 'market_rumor:item:put'
  45.                 'enable_max_depth' => true
  46.             ],
  47.             'denormalization_context' => [
  48.                 'groups' => 'market_rumor:item:put'
  49.                 'enable_max_depth' => true
  50.             ],
  51.         ],
  52.         'delete' => [
  53.             'security' => "
  54.                 is_granted('ROLE_ADMIN') or 
  55.                 is_granted('ROLE_INTERN') or 
  56.                 is_granted('ROLE_RESEARCH_ANALYST') or 
  57.                 is_granted('ROLE_BROKER')
  58.             ",
  59.         ],
  60.     ],
  61.     collectionOperations: [
  62.         'get' => [
  63.             'security' => "
  64.                 is_granted('ROLE_ADMIN') or 
  65.                 is_granted('ROLE_OPERATOR') or
  66.                 is_granted('ROLE_OPERATIONS_COORDINATOR') or 
  67.                 is_granted('ROLE_RESEARCH_ANALYST') or
  68.                 is_granted('ROLE_BROKER') or 
  69.                 is_granted('ROLE_INTERN')
  70.             ",
  71.             'normalization_context' => [
  72.                 'groups' => [
  73.                     'market_rumor:collection:get'
  74.                     'createdAt'
  75.                 ],
  76.                 'enable_max_depth' => true,
  77.             ],
  78.         ],
  79.         'post' => [
  80.             'security' => "
  81.                 is_granted('ROLE_ADMIN') or 
  82.                 is_granted('ROLE_INTERN') or 
  83.                 is_granted('ROLE_RESEARCH_ANALYST') or 
  84.                 is_granted('ROLE_BROKER')
  85.             ",
  86.             'normalization_context' => [
  87.                 'groups' => 'market_rumor:collection:post'
  88.                 'enable_max_depth' => true
  89.             ],
  90.             'denormalization_context' => [
  91.                 'groups' => 'market_rumor:collection:post'
  92.                 'enable_max_depth' => true
  93.             ],
  94.         ],
  95.     ],
  96. )]
  97. #[ApiFilter(
  98.     SearchFilter::class,
  99.     properties: [
  100.         'registerDate' => 'start',
  101.         'vessel.vesselName' => 'partial',
  102.         'charterer.companyName' => 'partial',
  103.         'owner.companyName' => 'partial',
  104.         'broker' => 'partial',
  105.         'laycanStartDate' => 'start',
  106.         'laycanEndDate' => 'start',
  107.         'status' => 'exact',
  108.         'createdAt' => 'start'
  109.     ],
  110. )]
  111. #[ApiFilter(
  112.     OrderFilter::class,
  113.     properties: [
  114.         'registerDate',
  115.         'vessel.vesselName',
  116.         'charterer.companyName',
  117.         'owner.companyName',
  118.         'broker',
  119.         'laycanStartDate',
  120.         'laycanEndDate',
  121.         'status',
  122.         'createdAt'
  123.     ],
  124. )]
  125. class MarketRumor
  126. {
  127.     use TimestampableEntity;
  128.     public const COST_TYPE_PMT 'PMT';    
  129.     public const COST_TYPE_LUMPSUM 'LUMPSUM';    
  130.     public const COST_TYPE_WS 'WS';    
  131.     public const COST_TYPE_TC 'TC';
  132.     public const COST_TYPES = [
  133.         self::COST_TYPE_PMT,
  134.         self::COST_TYPE_LUMPSUM,
  135.         self::COST_TYPE_WS,
  136.         self::COST_TYPE_TC,
  137.     ];
  138.     public const MARKET_RUMOR_STATUS_QUOTED 'QUOTED';
  139.     public const MARKET_RUMOR_STATUS_IN_MARKET 'IN_MARKET';
  140.     public const MARKET_RUMOR_STATUS_RUMORED 'RUMORED';
  141.     public const MARKET_RUMOR_STATUS_ON_SUBS 'ON_SUBS';
  142.     public const MARKET_RUMOR_STATUS_FIXED 'FIXED';
  143.     public const MARKET_RUMOR_STATUSES = [
  144.         self::MARKET_RUMOR_STATUS_QUOTED,
  145.         self::MARKET_RUMOR_STATUS_IN_MARKET,
  146.         self::MARKET_RUMOR_STATUS_RUMORED,
  147.         self::MARKET_RUMOR_STATUS_ON_SUBS,
  148.         self::MARKET_RUMOR_STATUS_FIXED,
  149.     ];
  150.     
  151.     #[ORM\Id]
  152.     #[ORM\GeneratedValue(strategy'NONE')]
  153.     #[ORM\Column(type'uuid'uniquetrue)]
  154.     private ?UuidInterface $id null;
  155.     #[ORM\Column(type'date'nullabletrue)]
  156.     #[ApiProperty()]
  157.     // #[Assert\NotBlank]
  158.     #[Assert\Type(\DateTimeInterface::class)]
  159.     #[Groups([
  160.         'market_rumor:item:get'
  161.         'market_rumor:item:put'
  162.         'market_rumor:collection:get'
  163.         'market_rumor:collection:post'
  164.     ])]
  165.     private ?\DateTimeInterface $registerDate null;
  166.     #[ORM\Column(type'string'nullabletrue)]
  167.     ##[Assert\NotNull]
  168.     ##[Assert\Type('string')]
  169.     #[ApiProperty()]
  170.     #[Groups([
  171.         'market_rumor:item:get'
  172.         'market_rumor:item:put'
  173.         'market_rumor:collection:get'
  174.         'market_rumor:collection:post'
  175.     ])]
  176.     private ?string $dwt null;
  177.     #[ORM\Column(type'date'nullabletrue)]
  178.     #[ApiProperty()]
  179.     // #[Assert\NotBlank]
  180.     #[Assert\Type(\DateTimeInterface::class)]
  181.     #[Groups([
  182.         'market_rumor:item:get'
  183.         'market_rumor:item:put'
  184.         'market_rumor:collection:get'
  185.         'market_rumor:collection:post'
  186.     ])]
  187.     private ?\DateTimeInterface $laycanStartDate null;
  188.     #[ORM\Column(type'date'nullabletrue)]
  189.     #[ApiProperty()]
  190.     // #[Assert\NotBlank]
  191.     #[Assert\Type(\DateTimeInterface::class)]
  192.     #[Groups([
  193.         'market_rumor:item:get'
  194.         'market_rumor:item:put'
  195.         'market_rumor:collection:get'
  196.         'market_rumor:collection:post'
  197.     ])]
  198.     private ?\DateTimeInterface $laycanEndDate null;
  199.     #[ORM\ManyToOne(
  200.         targetEntityVessel::class, 
  201.         inversedBy'marketRumors'
  202.     )]
  203.     #[ORM\JoinColumn(nullabletrue)]
  204.     #[ApiProperty()]
  205.     #[Groups([
  206.         'market_rumor:item:get'
  207.         'market_rumor:item:put'
  208.         'market_rumor:collection:get'
  209.         'market_rumor:collection:post'
  210.     ])]
  211.     private ?Vessel $vessel null;
  212.     #[ORM\ManyToOne(
  213.         targetEntityOwner::class, 
  214.         inversedBy'marketRumors'
  215.     )]
  216.     #[ORM\JoinColumn(nullabletrue)]
  217.     #[ApiProperty()]
  218.     #[Groups([
  219.         'market_rumor:item:get'
  220.         'market_rumor:item:put'
  221.         'market_rumor:collection:get'
  222.         'market_rumor:collection:post'
  223.     ])]
  224.     #[MaxDepth(1)]
  225.     private ?Owner $owner null;
  226.     #[ORM\ManyToOne(
  227.         targetEntityCharterer::class, 
  228.         inversedBy'marketRumors'
  229.     )]
  230.     #[ORM\JoinColumn(nullabletrue)]
  231.     #[ApiProperty()]
  232.     #[Groups([
  233.         'market_rumor:item:get'
  234.         'market_rumor:item:put'
  235.         'market_rumor:collection:get'
  236.         'market_rumor:collection:post'
  237.     ])]
  238.     #[MaxDepth(1)]
  239.     private ?Charterer $charterer null;
  240.     #[ORM\ManyToOne(
  241.         targetEntityCharterer::class, 
  242.         inversedBy'marketRumors2'
  243.     )]
  244.     #[ORM\JoinColumn(nullabletrue)]
  245.     #[ApiProperty()]
  246.     #[Groups([
  247.         'market_rumor:item:get'
  248.         'market_rumor:item:put'
  249.         'market_rumor:collection:get'
  250.         'market_rumor:collection:post'
  251.     ])]
  252.     #[MaxDepth(1)]
  253.     private ?Charterer $charterer2 null;
  254.     // #[ORM\ManyToOne(
  255.     //     targetEntity: User::class, 
  256.     //     inversedBy: 'marketRumors'
  257.     // )]
  258.     // #[ORM\JoinColumn(nullable: true)]
  259.     // #[ApiProperty()]
  260.     // #[Groups([
  261.     //     'market_rumor:item:get', 
  262.     //     'market_rumor:item:put', 
  263.     //     'market_rumor:collection:get', 
  264.     //     'market_rumor:collection:post'
  265.     // ])]
  266.     // #[MaxDepth(1)]
  267.     // private ?User $broker = null;
  268.     #[ORM\Column(type'string'nullabletrue)]
  269.     ##[Assert\NotNull]
  270.     ##[Assert\Type('string')]
  271.     #[ApiProperty()]
  272.     #[Groups([
  273.         'market_rumor:item:get'
  274.         'market_rumor:item:put'
  275.         // 'market_rumor:collection:get', 
  276.         'market_rumor:collection:post'
  277.     ])]
  278.     private ?string $broker null;
  279.     #[ORM\Column(type'string'nullablefalse)]
  280.     #[ApiProperty()]
  281.     #[Assert\NotBlank]
  282.     #[Assert\Type('string')]
  283.     #[Assert\Choice(
  284.         choicesself::MARKET_RUMOR_STATUSES
  285.         message'The status is not valid.'
  286.     )]
  287.     #[Groups([
  288.         'market_rumor:item:get'
  289.         'market_rumor:item:put'
  290.         'market_rumor:collection:get'
  291.         'market_rumor:collection:post'
  292.     ])]
  293.     private ?string $status null;
  294.     #[ORM\Column(type'string'nullabletrue)]
  295.     #[Assert\Type('string')]
  296.     #[ApiProperty()]
  297.     #[Groups([
  298.         'market_rumor:item:get'
  299.         'market_rumor:item:put'
  300.         'market_rumor:collection:get'
  301.         'market_rumor:collection:post'
  302.     ])]
  303.     private ?string $freightCost null;
  304.     #[ORM\Column(type'string'nullabletrue)]
  305.     #[Assert\Type('string')]
  306.     #[ApiProperty()]
  307.     #[Groups([
  308.         'market_rumor:item:get'
  309.         'market_rumor:item:put'
  310.         'market_rumor:collection:get'
  311.         'market_rumor:collection:post'
  312.     ])]
  313.     private ?string $freightCostCurrency null;
  314.     #[ORM\Column(type'string'nullabletrue)]
  315.     #[Assert\Type('string')]
  316.     #[Assert\Choice(
  317.         choicesself::COST_TYPES
  318.         message'The type is not valid.'
  319.     )]
  320.     #[ApiProperty()]
  321.     #[Groups([
  322.         'market_rumor:item:get'
  323.         'market_rumor:item:put'
  324.         'market_rumor:collection:get'
  325.         'market_rumor:collection:post'
  326.     ])]
  327.     private ?string $freightType null;
  328.     #[ORM\OneToMany(
  329.         targetEntityMarketRumorPort::class, 
  330.         mappedBy'marketRumor'
  331.         cascade: ['persist''remove'], 
  332.         orphanRemovaltrue
  333.     )]
  334.     #[ORM\OrderBy(['portIndex' => 'ASC'])]
  335.     #[Groups([
  336.         'market_rumor:item:get'
  337.         'market_rumor:item:put'
  338.         // 'market_rumor:collection:get', 
  339.         'market_rumor:collection:post'
  340.     ])]
  341.     #[MaxDepth(1)]
  342.     private ?Collection $portCalls null;
  343.     #[ORM\OneToMany(
  344.         targetEntityMarketRumorCargo::class, 
  345.         mappedBy'marketRumor'
  346.         cascade: ['persist''remove'], 
  347.         orphanRemovaltrue
  348.     )]
  349.     ##[ORM\OrderBy(['taskIndex' => 'ASC'])]
  350.     #[Groups([
  351.         'market_rumor:item:get'
  352.         'market_rumor:item:put'
  353.         // 'market_rumor:collection:get', 
  354.         'market_rumor:collection:post'
  355.     ])]
  356.     #[MaxDepth(1)]
  357.     private ?Collection $cargoItems null;
  358.     #[ORM\Column(type'text'nullabletrue)]
  359.     #[ApiProperty()]
  360.     #[Assert\Type('string')]
  361.     #[Groups([
  362.         'market_rumor:item:get'
  363.         'market_rumor:item:put'
  364.         'market_rumor:collection:get'
  365.         'market_rumor:collection:post'
  366.     ])]
  367.     private ?string $notes null;
  368.     #[ApiProperty()]
  369.     #[Groups([
  370.         'market_rumor:collection:get'
  371.         'market_rumor:item:get'
  372.     ])]
  373.     private ?string $loadPortsResume null;
  374.     #[ApiProperty()]
  375.     #[Groups([
  376.         'market_rumor:collection:get'
  377.         'market_rumor:item:get'
  378.     ])]
  379.     private ?string $dischargePortsResume null;
  380.     #[ApiProperty()]
  381.     #[Groups([
  382.         'market_rumor:collection:get'
  383.         'market_rumor:item:get'
  384.     ])]
  385.     private ?string $cargoResume null;
  386.     #[ApiProperty()]
  387.     #[Groups([
  388.         'market_rumor:collection:get'
  389.         'market_rumor:item:get'
  390.     ])]
  391.     private ?string $cargoVolumeM3 null;
  392.     #[ApiProperty()]
  393.     #[Groups([
  394.         'market_rumor:collection:get'
  395.         'market_rumor:item:get'
  396.     ])]
  397.     private ?string $cargoVolumeMT null;
  398.     public function __construct()
  399.     {
  400.         $this->id Uuid::uuid4();
  401.         $this->portCalls = new ArrayCollection();
  402.         $this->cargoItems = new ArrayCollection();
  403.     }
  404.     public function getId(): ?UuidInterface
  405.     {
  406.         return $this->id;
  407.     }
  408.     public function setRegisterDate(?\DateTimeInterface $registerDate): void
  409.     {
  410.         $this->registerDate $registerDate;
  411.     }
  412.     public function getRegisterDate(): ?string
  413.     {
  414.         return $this->registerDate?->format('Y-m-d');
  415.     }
  416.     public function setLaycanStartDate(?\DateTimeInterface $laycanStartDate): void
  417.     {
  418.         $this->laycanStartDate $laycanStartDate;
  419.     }
  420.     public function getLaycanStartDate(): ?string
  421.     {
  422.         return $this->laycanStartDate?->format('Y-m-d');
  423.     }
  424.     public function setLaycanEndDate(?\DateTimeInterface $laycanEndDate): void
  425.     {
  426.         $this->laycanEndDate $laycanEndDate;
  427.     }
  428.     public function getLaycanEndDate(): ?string
  429.     {
  430.         return $this->laycanEndDate?->format('Y-m-d');
  431.     }
  432.     public function setDwt(?string $dwt): void
  433.     {
  434.         $this->dwt $dwt;
  435.     }
  436.     public function getDwt(): ?string
  437.     {
  438.         return $this->dwt;
  439.     }
  440.     public function setVessel(?Vessel $vessel): void
  441.     {
  442.         $this->vessel $vessel;
  443.     }
  444.     public function getVessel(): ?Vessel
  445.     {
  446.         return $this->vessel;
  447.     }
  448.     public function setOwner(?Owner $owner): void
  449.     {
  450.         $this->owner $owner;
  451.     }
  452.     public function getOwner(): ?Owner
  453.     {
  454.         return $this->owner;
  455.     }
  456.     public function setCharterer(?Charterer $charterer): void
  457.     {
  458.         $this->charterer $charterer;
  459.     }
  460.     public function getCharterer(): ?Charterer
  461.     {
  462.         return $this->charterer;
  463.     }
  464.     public function setCharterer2(?Charterer $charterer): void
  465.     {
  466.         $this->charterer2 $charterer;
  467.     }
  468.     public function getCharterer2(): ?Charterer
  469.     {
  470.         return $this->charterer2;
  471.     }
  472.     public function setBroker(?string $broker): void
  473.     {
  474.         $this->broker $broker;
  475.     }
  476.     public function getBroker(): ?string
  477.     {
  478.         return $this->broker;
  479.     }
  480.     public function addPortCall(MarketRumorPort $portCall): void
  481.     {
  482.         $portCall->setMarketRumor($this);
  483.         $this->portCalls[] = $portCall;
  484.     }
  485.     public function removePortCall(MarketRumorPort $portCall): void
  486.     {
  487.         $this->portCalls->removeElement($portCall);
  488.     }
  489.     public function getPortCalls(): Collection
  490.     {
  491.         return $this->portCalls;
  492.     }
  493.     public function addCargoItem(MarketRumorCargo $cargoItem): void
  494.     {
  495.         $cargoItem->setMarketRumor($this);
  496.         $this->cargoItems[] = $cargoItem;
  497.     }
  498.     public function removeCargoItem(MarketRumorCargo $cargoItem): void
  499.     {
  500.         $this->cargoItems->removeElement($cargoItem);
  501.     }
  502.     public function getCargoItems(): Collection
  503.     {
  504.         return $this->cargoItems;
  505.     }
  506.     public function getFreightCost(): ?string
  507.     {
  508.         return $this->freightCost;
  509.     }
  510.     public function setFreightCost(?string $freightCost): void
  511.     {
  512.         $this->freightCost $freightCost;
  513.     }
  514.     public function getFreightCostCurrency(): ?string
  515.     {
  516.         return $this->freightCostCurrency;
  517.     }
  518.     public function setFreightCostCurrency(?string $freightCostCurrency): void
  519.     {
  520.         $this->freightCostCurrency $freightCostCurrency;
  521.     }
  522.     public function getFreightType(): ?string
  523.     {
  524.         return $this->freightType;
  525.     }
  526.     public function setFreightType(?string $freightType): void
  527.     {
  528.         $this->freightType $freightType;
  529.     }
  530.     public function setStatus(?string $status): void
  531.     {
  532.         $this->status $status;
  533.     }
  534.     public function getStatus(): ?string
  535.     {
  536.         return $this->status;
  537.     }
  538.     public function setNotes(?string $notes): void
  539.     {
  540.         $this->notes $notes;
  541.     }
  542.     public function getNotes(): ?string
  543.     {
  544.         return $this->notes;
  545.     }
  546.     public function getLoadPortsResume(): ?string
  547.     {
  548.         $portCalls array_filter($this->getPortCalls()->toArray(), function($pc) {
  549.             return $pc->getPortCallType() === PortCall::PORT_CALL_TYPE_LOAD;
  550.         });
  551.         $portCount count($portCalls);
  552.         if ($portCount === 0) {
  553.             return null;
  554.         }
  555.         $portCall reset($portCalls);
  556.         $portName $portCall $portCall->getPort()->getPortName() : '';
  557.         $portSuffix $portCount ' (+)' '';
  558.         return $portName $portSuffix;
  559.     }
  560.     public function getDischargePortsResume(): ?string
  561.     {
  562.         $portCalls array_filter($this->getPortCalls()->toArray(), function($pc) {
  563.             return $pc->getPortCallType() === PortCall::PORT_CALL_TYPE_DISCHARGE;
  564.         });
  565.         
  566.         $portCount count($portCalls);
  567.         if ($portCount === 0) {
  568.             return null;
  569.         }
  570.         $portCall reset($portCalls);
  571.         $portName $portCall $portCall->getPort()->getPortName() : '';
  572.         $portSuffix $portCount ' (+)' '';
  573.         return $portName $portSuffix;
  574.     }
  575.     public function getCargoResume(): ?string
  576.     {
  577.         $cargoCount $this->getCargoItems()->count();
  578.         if ($cargoCount === 0) {
  579.             return null;
  580.         }
  581.         $cargoItems $this->getCargoItems();
  582.         $cargoItem $cargoItems->first();
  583.         if (!$cargoItem instanceof MarketRumorCargo) {
  584.             return null;
  585.         }
  586.         $cargoName $cargoItem->getCargo()->getName();
  587.         $cargoSuffix $cargoCount ' (+)' '';
  588.         return $cargoName $cargoSuffix;
  589.     }
  590.     public function getCargoVolumeM3(): ?string
  591.     {
  592.         $totalVolume 0.0;
  593.         foreach ($this->getCargoItems() as $cargoItem) {
  594.             // $totalVolume += (float) $cargoItem->getQuantityM3();
  595.             $totalVolume += (float) str_replace(',''.'str_replace('.'''$cargoItem->getQuantityM3() ?? ''));
  596.         }
  597.         // return number_format($totalVolume, 3, '.', '');
  598.         return $totalVolume str_replace(',00'''number_format($totalVolume2',''.')) : null;
  599.     }
  600.     public function getCargoVolumeMT(): ?string
  601.     {
  602.         $totalVolume 0.0;
  603.         foreach ($this->getCargoItems() as $cargoItem) {
  604.             // $totalVolume += (float) $cargoItem->getQuantityMT();
  605.             $totalVolume += (float) str_replace(',''.'str_replace('.'''$cargoItem->getQuantityMT() ?? ''));
  606.         }
  607.         // return number_format($totalVolume, 3, '.', '');
  608.         return $totalVolume str_replace(',00'''number_format($totalVolume2',''.')) : null;
  609.     }
  610. }