vendor/crosiersource/crosierlib-radx/src/Entity/Financeiro/CaixaOperacao.php line 65

Open in your IDE?
  1. <?php
  2. namespace CrosierSource\CrosierLibRadxBundle\Entity\Financeiro;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  8. use CrosierSource\CrosierLibBaseBundle\Doctrine\Annotations\EntityHandler;
  9. use CrosierSource\CrosierLibBaseBundle\Doctrine\Annotations\NotUppercase;
  10. use CrosierSource\CrosierLibBaseBundle\Entity\EntityId;
  11. use CrosierSource\CrosierLibBaseBundle\Entity\EntityIdTrait;
  12. use CrosierSource\CrosierLibBaseBundle\Entity\Security\User;
  13. use DateTime;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. use Symfony\Component\Serializer\Annotation\MaxDepth;
  17. use Symfony\Component\Serializer\Annotation\SerializedName;
  18. use Symfony\Component\Validator\Constraints as Assert;
  19. /**
  20.  * Entidade 'CaixaOperacao'.
  21.  *
  22.  * @ApiResource(
  23.  *     normalizationContext={"groups"={"caixaOperacao","carteira","entityId"},"enable_max_depth"=true},
  24.  *     denormalizationContext={"groups"={"caixaOperacao"},"enable_max_depth"=true},
  25.  *
  26.  *     itemOperations={
  27.  *          "get"={"path"="/fin/caixaOperacao/{id}", "security"="is_granted('ROLE_FINAN')"},
  28.  *          "put"={"path"="/fin/caixaOperacao/{id}", "security"="is_granted('ROLE_FINAN')"},
  29.  *          "delete"={"path"="/fin/caixaOperacao/{id}", "security"="is_granted('ROLE_FINAN_ADMIN')"}
  30.  *     },
  31.  *     collectionOperations={
  32.  *          "get"={"path"="/fin/caixaOperacao", "security"="is_granted('ROLE_FINAN')"},
  33.  *          "post"={"path"="/fin/caixaOperacao", "security"="is_granted('ROLE_FINAN')"}
  34.  *     },
  35.  *
  36.  *     attributes={
  37.  *          "pagination_items_per_page"=10,
  38.  *          "formats"={"jsonld", "csv"={"text/csv"}}
  39.  *     }
  40.  *
  41.  * )
  42.  * @ApiFilter(PropertyFilter::class)
  43.  *
  44.  *
  45.  * @ApiFilter(SearchFilter::class, properties={
  46.  *     "carteira": "exact",
  47.  *     "responsavel.nome": "partial",
  48.  *     "id": "exact",
  49.  *     "operacao": "exact",
  50.  *     "dtOperacao": "exact"
  51.  * })
  52.  *
  53.  * @ApiFilter(OrderFilter::class, properties={"id", "carteira.descricao", "operacao", "dtOperacao", "responsavel.nome"}, arguments={"orderParameterName"="order"})
  54.  *
  55.  * @EntityHandler(entityHandlerClass="CrosierSource\CrosierLibRadxBundle\EntityHandler\Financeiro\CaixaOperacaoEntityHandler")
  56.  *
  57.  * @ORM\Entity(repositoryClass="CrosierSource\CrosierLibRadxBundle\Repository\Financeiro\CaixaOperacaoRepository")
  58.  * @ORM\Table(name="fin_caixa_operacao")
  59.  *
  60.  * @author Carlos Eduardo Pauluk
  61.  */
  62. class CaixaOperacao implements EntityId
  63. {
  64.     use EntityIdTrait;
  65.     /**
  66.      * @ORM\Column(name="uuid", type="string", nullable=false, length=36)
  67.      * @NotUppercase()
  68.      * @Groups("procedimento")
  69.      * @Assert\Length(min=36, max=36)
  70.      *
  71.      * @var string|null
  72.      */
  73.     public ?string $UUID null;
  74.     /**
  75.      * @ORM\ManyToOne(targetEntity="CrosierSource\CrosierLibRadxBundle\Entity\Financeiro\Carteira")
  76.      * @ORM\JoinColumn(name="carteira_id")
  77.      * @Groups("caixaOperacao")
  78.      * @MaxDepth(2)
  79.      * @var Carteira|null
  80.      */
  81.     public ?Carteira $carteira null;
  82.     /**
  83.      * ABERTURA / FECHAMENTO / CONFERÊNCIA
  84.      * @ORM\Column(name="operacao", type="string", nullable=false, length=20)
  85.      * @Groups("caixaOperacao")
  86.      * @var null|string
  87.      */
  88.     public ?string $operacao null;
  89.     /**
  90.      * @ORM\Column(name="obs", type="string", nullable=true, length=255)
  91.      * @Groups("caixaOperacao")
  92.      * @var null|string
  93.      */
  94.     public ?string $obs null;
  95.     /**
  96.      * @ORM\Column(name="dt_operacao", type="datetime", nullable=false)
  97.      * @Groups("caixaOperacao")
  98.      * @Assert\Type("\DateTime")
  99.      * @Assert\NotNull()
  100.      *
  101.      * @var DateTime|null
  102.      */
  103.     public ?DateTime $dtOperacao null;
  104.     /**
  105.      * @ORM\ManyToOne(targetEntity="CrosierSource\CrosierLibBaseBundle\Entity\Security\User")
  106.      * @ORM\JoinColumn(name="responsavel_id")
  107.      * @MaxDepth(2)
  108.      * @Groups("caixaOperacao")
  109.      * @var User|null
  110.      */
  111.     public ?User $responsavel null;
  112.     /**
  113.      * @ORM\ManyToOne(targetEntity="CrosierSource\CrosierLibBaseBundle\Entity\Security\User")
  114.      * @ORM\JoinColumn(name="responsavel_dest_id")
  115.      * @MaxDepth(2)
  116.      * @Groups("caixaOperacao")
  117.      * @var User|null
  118.      */
  119.     public ?User $responsavelDest null;
  120.     /**
  121.      * @ORM\Column(name="valor", type="decimal", nullable=false, precision=15, scale=2)
  122.      * @Groups("N")
  123.      * @Assert\NotNull()
  124.      * @Assert\Type(type="string")
  125.      * @var null|string
  126.      */
  127.     public ?string $valor null;
  128.     /**
  129.      *
  130.      * @ORM\Column(name="json_data", type="json")
  131.      * @NotUppercase()
  132.      * @Groups("caixaOperacao")
  133.      *
  134.      * @var null|array
  135.      */
  136.     public ?array $jsonData null;
  137.     /**
  138.      * Para aceitar tanto em string quanto em double.
  139.      * @Groups("caixaOperacao")
  140.      * @SerializedName("valor")
  141.      * @return float
  142.      */
  143.     public function getValorFormatted(): float
  144.     {
  145.         return (float)$this->valor;
  146.     }
  147.     /**
  148.      * Para aceitar tanto em string quanto em double.
  149.      * @Groups("caixaOperacao")
  150.      * @SerializedName("valor")
  151.      * @param float $valor
  152.      */
  153.     public function setValorFormatted(float $valor)
  154.     {
  155.         $this->valor $valor;
  156.     }
  157.     /**
  158.      * @Groups("caixaOperacao")
  159.      */
  160.     public function getStatus(): string
  161.     {
  162.         if ($this->operacao === 'ABERTURA') {
  163.             return 'ABERTO';
  164.         }
  165.         return 'FECHADO';
  166.     }
  167. }