src/Entity/Account.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\EntityManager;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\Serializer\Annotation\Groups;
  6. /**
  7.  * Account
  8.  *
  9.  * @ORM\Table(name="account")
  10.  * @ORM\Entity(repositoryClass="App\Repository\AccountRepository")
  11.  */
  12. class Account //extends OrmEntity
  13. {
  14.     const debit 1;
  15.     const credit 0;
  16.     /**
  17.      * @var \Ramsey\Uuid\UuidInterface
  18.      *
  19.      * @ORM\Id
  20.      * @ORM\Column(type="uuid", unique=true)
  21.      * @ORM\GeneratedValue(strategy="CUSTOM")
  22.      * @ORM\CustomIdGenerator(class="Ramsey\Uuid\Doctrine\UuidGenerator")
  23.      * @Groups("Moviment")
  24.      */
  25.     private $id;
  26.     /**
  27.      * @var int
  28.      *
  29.      * @ORM\Column(name="code", type="integer")
  30.      * @Groups("Moviment")
  31.      */
  32.     private $code;
  33.     /**
  34.      * @var string
  35.      *
  36.      * @ORM\Column(name="description", type="string", nullable=true, length=255)
  37.      */
  38.     private $description;
  39.     /**
  40.      * @var string
  41.      *
  42.      * @ORM\Column(name="name", type="string", length=100)
  43.      */
  44.     private $name;
  45.     /**
  46.      *
  47.      * @ORM\Column(name="natureza",nullable=true, type="boolean")
  48.      */
  49.     private $natureza;
  50.     /**
  51.      * @ORM\ManyToOne(targetEntity="App\Entity\Account", inversedBy="account")
  52.      */
  53.     private $account;
  54.     /**
  55.      * @ORM\ManyToOne(targetEntity="App\Entity\AccountClass", inversedBy="accountClass")
  56.      */
  57.     private $accountClass;
  58.     /**
  59.      * @ORM\OneToMany(targetEntity="App\Entity\Account", mappedBy="account")
  60.      * @ORM\OrderBy({"code" = "ASC"})
  61.      */
  62.     private $accounts;
  63.     /**
  64.      * @ORM\OneToMany(targetEntity="App\Entity\Moviment", mappedBy="account")
  65.      */
  66.     private $moviments;
  67.     /**
  68.      * @var string
  69.      * @Groups("Moviment")
  70.      */
  71.     private $fullCode;
  72.     /**
  73.      * @var string
  74.      */
  75.     private $amount;
  76.     private $credit;
  77.     private $debit;
  78.     /**
  79.      * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="user")
  80.      */
  81.     private $user;
  82.     /**
  83.      * @var \DateTime
  84.      *
  85.      * @ORM\Column(name="date", type="datetime", nullable=true)
  86.      */
  87.     private $date;
  88.     /**
  89.      * @var bool
  90.      *
  91.      * @ORM\Column(name="is_active",nullable=true, type="boolean")
  92.      */
  93.     private $isActive;
  94.     private $initialCredit;
  95.     private $finalCredit;
  96.     /**
  97.      * Account constructor.
  98.      * @param bool $isActive
  99.      * @throws \Exception
  100.      */
  101.     public function __construct()
  102.     {
  103.         $this->isActive true;
  104.                 //parent::__construct();
  105.     }
  106.     /**
  107.      * @return \Ramsey\Uuid\UuidInterface
  108.      */
  109.     public function getId()
  110.     {
  111.         return $this->id;
  112.     }
  113.     /**
  114.      * @return Account
  115.      */
  116.     public function setId($id)
  117.     {
  118.         $this->id $id;
  119.         return $this;
  120.     }
  121.     /**
  122.      * Set code
  123.      *
  124.      * @param integer $code
  125.      *
  126.      * @return Account
  127.      */
  128.     public function setCode($code)
  129.     {
  130.         $this->code $code;
  131.         return $this;
  132.     }
  133.     /**
  134.      * Get code
  135.      *
  136.      * @return int
  137.      */
  138.     public function getCode()
  139.     {
  140.         return $this->code;
  141.     }
  142.     /**
  143.      * @return string
  144.      */
  145.     public function getName()
  146.     {
  147.         return $this->name;
  148.     }
  149.     /**
  150.      * @param string $name
  151.      */
  152.     public function setName(string $name)
  153.     {
  154.         $this->name $name;
  155.         return $this;
  156.     }
  157.     /**
  158.      * @return string
  159.      */
  160.     public function getFullCode()
  161.     {
  162.         if (is_null($this->getAccount()))
  163.             $this->fullCode is_null($this->getAccountClass()) ? '' $this->getAccountClass()->getCode() . $this->getCode();
  164.         else
  165.             $this->fullCode $this->getAccount()->getFullCode() . '.' $this->getCode();
  166.         return $this->fullCode;
  167.     }
  168.     /**
  169.      * @param mixed $fullCode
  170.      */
  171.     public function setFullCode()
  172.     {
  173.         $this->fullCode $this->getAccount()->getFullCode() . '.' $this->getCode();
  174.     }
  175.     /**
  176.      * Set description
  177.      *
  178.      * @param string $description
  179.      *
  180.      * @return Account
  181.      */
  182.     public function setDescription($description)
  183.     {
  184.         $this->description $description;
  185.         return $this;
  186.     }
  187.     /**
  188.      * Get description
  189.      *
  190.      * @return string
  191.      */
  192.     public function getDescription()
  193.     {
  194.         return $this->description;
  195.     }
  196.     /**
  197.      * Set natureza
  198.      *
  199.      * @param integer $natureza
  200.      *
  201.      * @return Account
  202.      */
  203.     public function setNatureza($natureza)
  204.     {
  205.         $this->natureza $natureza;
  206.         return $this;
  207.     }
  208.     /**
  209.      * Get natureza
  210.      *
  211.      */
  212.     public function getNatureza()
  213.     {
  214.         return $this->natureza;
  215.     }
  216.     /**
  217.      * Set account
  218.      *
  219.      * @param Account $account
  220.      *
  221.      * @return Account
  222.      */
  223.     public function setAccount($account)
  224.     {
  225.         $this->account $account;
  226.         return $this;
  227.     }
  228.     /**
  229.      * @return Account
  230.      */
  231.     public function getAccount()
  232.     {
  233.         return $this->account;
  234.     }
  235.     /**
  236.      * @return AccountClass
  237.      */
  238.     public function getAccountClass()
  239.     {
  240.         return $this->accountClass;
  241.     }
  242.     /**
  243.      * @param AccountClass $accountClass
  244.      */
  245.     public function setAccountClass($accountClass)
  246.     {
  247.         $this->accountClass $accountClass;
  248.     }
  249.     /**
  250.      * @return User
  251.      */
  252.     public function getUser()
  253.     {
  254.         return $this->user;
  255.     }
  256.     /**
  257.      * @param mixed $user
  258.      */
  259.     public function setUser($user)
  260.     {
  261.         $this->user $user;
  262.         return $this;
  263.     }
  264.     /**
  265.      * @return \DateTime
  266.      */
  267.     public function getDate()
  268.     {
  269.         return $this->date;
  270.     }
  271.     /**
  272.      * @param \DateTime $date
  273.      */
  274.     public function setDate($date)
  275.     {
  276.         $this->date $date;
  277.     }
  278.     /**
  279.      * @return Account[]
  280.      */
  281.     public function getAccounts()
  282.     {
  283.         return $this->accounts;
  284.     }
  285.     /**
  286.      * @param Account[] $accounts
  287.      * @return Account
  288.      */
  289.     public function setAccounts($accounts)
  290.     {
  291.         $this->accounts $accounts;
  292.         return $this;
  293.     }
  294.     /**
  295.      * @return float
  296.      */
  297.     public function getAmount()
  298.     {
  299.         /*$this->amount = $this->getDebit()-$this->getCredit();
  300.         return $this->amount;*/
  301.         $amount 0;
  302.         if ($this->getFullCode() == '61')
  303.             $t 0;
  304.         if (!empty($this->getMoviments()))
  305.             foreach ($this->getMoviments() as $moviment) {
  306.                 if ($moviment->getTransactionNature())
  307.                     $amount -= $moviment->getAmount();
  308.                 else
  309.                     $amount += $moviment->getAmount();
  310.             }
  311.         foreach ($this->getAccounts() as $account)
  312.             $amount += $account->getAmount();
  313.         $this->amount $amount;
  314.         return $this->amount;
  315.     }
  316.     public $amounti;
  317.     /**
  318.      * @return float
  319.      */
  320.     public function getAmountFromTo($from null$to null)
  321.     {
  322.         /*$this->amount = $this->getDebit()-$this->getCredit();
  323.         return $this->amount;*/
  324.         $amount 0;
  325.         if ($this->getFullCode() == '61')
  326.             $t 0;
  327.         $moviments = [];
  328.         foreach ($this->getMoviments() as $moviment)
  329.             $moviments[] = $moviment;
  330.         $moviments array_filter($moviments,
  331.             function ($e) use (&$from, &$to) {
  332.                 return ($e->getTransaction()->getTransactionDate() >= $from or is_null($from)) and (is_null($to) or $e->getTransaction()->getTransactionDate() <= $to);
  333.             }
  334.         );
  335.         foreach ($moviments as $moviment) {
  336.             if ($moviment->getTransactionNature())
  337.                 $amount -= $moviment->getAmount();
  338.             else
  339.                 $amount += $moviment->getAmount();
  340.         }
  341.         foreach ($this->getAccounts() as $account)
  342.             $amount += $account->getAmountFromTo($from$to);
  343.         $this->amount $amount;
  344.         $this->amounti $amount;
  345.         return $this->amounti;
  346.     }
  347.     /**
  348.      * @return mixed
  349.      */
  350.     public function getDebit()
  351.     {
  352.         $amount 0;
  353.         $moviments $this->getMoviments();
  354.         if (count($moviments) > 1)
  355.             foreach ($moviments as $moviment) {
  356.                 if (!$moviment->getTransactionNature())
  357.                     $amount += $moviment->getAmount();
  358.             }
  359.         elseif (count($this->getAccounts()) > 0)
  360.             foreach ($this->getAccounts() as $account)
  361.                 $amount += $account->getDebit();
  362.         $this->debit $amount;
  363.         return $this->debit;
  364.     }
  365.     /**
  366.      * @return mixed
  367.      */
  368.     public function getCredit()
  369.     {
  370.         $amount 0;
  371.         $moviments $this->getMoviments();
  372.         if (count($moviments) > 1)
  373.             foreach ($moviments as $moviment) {
  374.                 if ($moviment->getTransactionNature())
  375.                     $amount += $moviment->getAmount();
  376.             }
  377.         elseif (count($this->getAccounts()) > 0)
  378.             foreach ($this->getAccounts() as $account)
  379.                 $amount += $account->getDebit();
  380.         $this->credit $amount;
  381.         return $this->credit;
  382.     }
  383.     /**
  384.      * @return Moviment[]
  385.      */
  386.     public function getMoviments()
  387.     {
  388.         return (is_null($this->moviments) ? [] : $this->moviments);
  389.     }
  390.     /**
  391.      * @param $moviments
  392.      * @return $this
  393.      */
  394.     public function setMoviments($moviments)
  395.     {
  396.         $this->moviments $moviments;
  397.         return $this;
  398.     }
  399.     public function build($from$to)
  400.     {
  401.         return $this;
  402.     }
  403.     /**
  404.      * @return mixed
  405.      */
  406.     public function getInitialCredit()
  407.     {
  408.         return $this->initialCredit;
  409.     }
  410.     /**
  411.      * @param mixed $initialCredit
  412.      */
  413.     public function setInitialCredit($initialCredit)
  414.     {
  415.         $this->initialCredit $initialCredit;
  416.     }
  417.     /**
  418.      * @return mixed
  419.      */
  420.     public function getFinalCredit()
  421.     {
  422.         return $this->getAmount();
  423.     }
  424.     /**
  425.      * @param mixed $finalCredit
  426.      */
  427.     public function setFinalCredit($finalCredit)
  428.     {
  429.         $this->finalCredit $finalCredit;
  430.     }
  431.     /**
  432.      * @return bool
  433.      */
  434.     public function isActive()
  435.     {
  436.         return $this->isActive;
  437.     }
  438.     /**
  439.      * @param bool $isActive
  440.      */
  441.     public function setIsActive($isActive)
  442.     {
  443.         $this->isActive $isActive;
  444.     }
  445. }