vendor/crosiersource/crosierlib-radx/src/Entity/Vendas/VendaItem.php line 51

Open in your IDE?
  1. <?php
  2. namespace CrosierSource\CrosierLibRadxBundle\Entity\Vendas;
  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\CrosierLibRadxBundle\Entity\Estoque\Produto;
  13. use CrosierSource\CrosierLibRadxBundle\Entity\Estoque\Unidade;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. /**
  17.  * @ApiResource(
  18.  *     normalizationContext={"groups"={"vendaItem","entityId"},"enable_max_depth"=true},
  19.  *     denormalizationContext={"groups"={"vendaItem"},"enable_max_depth"=true},
  20.  *
  21.  *     itemOperations={
  22.  *          "get"={"path"="/ven/vendaItem/{id}", "security"="is_granted('ROLE_VENDAS')"},
  23.  *          "put"={"path"="/ven/vendaItem/{id}", "security"="is_granted('ROLE_VENDAS')"},
  24.  *          "delete"={"path"="/ven/vendaItem/{id}", "security"="is_granted('ROLE_ADMIN')"}
  25.  *     },
  26.  *     collectionOperations={
  27.  *          "get"={"path"="/ven/vendaItem", "security"="is_granted('ROLE_VENDAS')"},
  28.  *          "post"={"path"="/ven/vendaItem", "security"="is_granted('ROLE_VENDAS')"}
  29.  *     },
  30.  *
  31.  *     attributes={
  32.  *          "pagination_items_per_page"=10,
  33.  *          "formats"={"jsonld", "csv"={"text/csv"}}
  34.  *     }
  35.  * )
  36.  * @ApiFilter(PropertyFilter::class)
  37.  *
  38.  * @ApiFilter(SearchFilter::class, properties={"nome": "partial", "documento": "exact", "id": "exact"})
  39.  * @ApiFilter(OrderFilter::class, properties={"id", "documento", "nome", "updated"}, arguments={"orderParameterName"="order"})
  40.  *
  41.  * @EntityHandler(entityHandlerClass="CrosierSource\CrosierLibRadxBundle\EntityHandler\Vendas\VendaItemEntityHandler")
  42.  *
  43.  * @ORM\Entity(repositoryClass="CrosierSource\CrosierLibRadxBundle\Repository\Vendas\VendaItemRepository")
  44.  * @ORM\Table(name="ven_venda_item")
  45.  *
  46.  * @author Carlos Eduardo Pauluk
  47.  */
  48. class VendaItem implements EntityId
  49. {
  50.     use EntityIdTrait;
  51.     /**
  52.      *
  53.      * @ORM\ManyToOne(targetEntity="CrosierSource\CrosierLibRadxBundle\Entity\Vendas\Venda", inversedBy="itens")
  54.      * @ORM\JoinColumn(name="venda_id", nullable=false)     *
  55.      *
  56.      * @var null|Venda
  57.      */
  58.     public ?Venda $venda null;
  59.     /**
  60.      *
  61.      * @ORM\Column(name="ordem", type="integer")
  62.      * @Groups("vendaItem")
  63.      *
  64.      * @var null|integer
  65.      */
  66.     public ?int $ordem null;
  67.     /**
  68.      *
  69.      * @ORM\Column(name="qtde", type="decimal", nullable=false)
  70.      * @Groups("vendaItem")
  71.      *
  72.      * @var null|float
  73.      */
  74.     public ?float $qtde null;
  75.     /**
  76.      *
  77.      * @ORM\ManyToOne(targetEntity="CrosierSource\CrosierLibRadxBundle\Entity\Estoque\Unidade")
  78.      * @ORM\JoinColumn(name="unidade_id", nullable=false)
  79.      *
  80.      * @var null|Unidade
  81.      */
  82.     public ?Unidade $unidade null;
  83.     /**
  84.      *
  85.      * @ORM\ManyToOne(targetEntity="CrosierSource\CrosierLibRadxBundle\Entity\Estoque\Produto")
  86.      * @ORM\JoinColumn(name="produto_id")
  87.      * @Groups("vendaItem")
  88.      *
  89.      * @var null|Produto
  90.      */
  91.     public ?Produto $produto null;
  92.     /**
  93.      *
  94.      * @ORM\Column(name="descricao", type="string")
  95.      * @Groups("vendaItem")
  96.      *
  97.      * @var null|string
  98.      */
  99.     public ?string $descricao null;
  100.     /**
  101.      *
  102.      * @ORM\Column(name="preco_venda", type="decimal")
  103.      * @Groups("vendaItem")
  104.      *
  105.      * @var null|float
  106.      */
  107.     public ?float $precoVenda null;
  108.     /**
  109.      *
  110.      * @ORM\Column(name="subtotal", type="decimal")
  111.      * @Groups("vendaItem")
  112.      *
  113.      * @var null|float
  114.      */
  115.     public ?float $subtotal null;
  116.     /**
  117.      *
  118.      * @ORM\Column(name="desconto", type="decimal")
  119.      * @Groups("vendaItem")
  120.      *
  121.      * @var null|float
  122.      */
  123.     public ?float $desconto null;
  124.     /**
  125.      * @ORM\Column(name="total", type="decimal")
  126.      * @Groups("vendaItem")
  127.      *
  128.      * @var null|float
  129.      */
  130.     public ?float $total null;
  131.     /**
  132.      *
  133.      * @ORM\Column(name="devolucao", type="boolean")
  134.      * @Groups("vendaItem")
  135.      *
  136.      * @var bool|null
  137.      */
  138.     public ?bool $devolucao false;
  139.     /**
  140.      *
  141.      * @ORM\Column(name="json_data", type="json")
  142.      * @var null|array
  143.      * @NotUppercase()
  144.      * @Groups("vendaItem")
  145.      */
  146.     public ?array $jsonData null;
  147.     public function getDescricaoMontadaResumida(int $tam 36)
  148.     {
  149.         $desc '[';
  150.         if (strlen($this->produto->codigo) > 6) {
  151.             $desc .= substr($this->produto->codigo, -6);
  152.         } else {
  153.             $desc .= str_pad($this->produto->codigo6'0'STR_PAD_LEFT);
  154.         }
  155.         $desc .= '] ';
  156.         if (strlen($this->produto->nome) > $tam) {
  157.             $desc .= substr($this->produto->nome0$tam 10) . '..' substr($this->produto->nome, -10);
  158.         } else {
  159.             $desc .= $this->produto->nome;
  160.         }
  161.         return mb_strtoupper($desc);
  162.     }
  163. }