src/Entity/Company.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. /**
  5.  * Company
  6.  * @ORM\Table(name="company", indexes={@ORM\Index(name="company_city_fk_1", columns={"co_city_id"}), @ORM\Index(name="company_user_fk_1", columns={"co_user_creator"})})
  7.  * @ORM\Entity(repositoryClass="App\Repository\CompanyRepository")
  8.  * @ORM\HasLifecycleCallbacks
  9.  */
  10. class Company {
  11.     const STATUS_ACTIVE 1;
  12.     const STATUS_INACTIVE 0;
  13.     const STATUS_SUSPENDED 2;
  14.     const STATUS_CANCELED 3;
  15.     const COMPANY_IS_KIJHO 1;
  16.     const COMPANY_NOT_CREATED_BY_CRM 0;
  17.     const COMPANY_CREATED_BY_CRM 1;
  18.     
  19.     const COMPANY_NOT_COMPLETED_BY_CRM 0;
  20.     const COMPANY_COMPLETED_BY_CRM 1;
  21.     const COMPANY_PAYMENT_MONTHLY 1;
  22.     const COMPANY_PRE_PAYMENT 2;
  23.     /**
  24.      * @var integer
  25.      * @ORM\Column(name="co_id", type="integer")
  26.      * @ORM\Id
  27.      * @ORM\GeneratedValue(strategy="IDENTITY")
  28.      */
  29.     private $id;
  30.     /**
  31.      * @var string
  32.      * @ORM\Column(name="co_company_name", type="string", length=100, nullable=false)
  33.      */
  34.     private $coCompanyName;
  35.     /**
  36.      * @var string
  37.      * @ORM\Column(name="co_address", type="string", length=100, nullable=true)
  38.      */
  39.     private $coAddress;
  40.     /**
  41.      * @var string
  42.      * @ORM\Column(name="co_company_identification", type="string", length=100, nullable=true)
  43.      */
  44.     private $coCompanyIdentification;
  45.     /**
  46.      * @var \DateTime
  47.      * @ORM\Column(name="co_date_created", type="datetime", nullable=false)
  48.      */
  49.     private $coDateCreated;
  50.     /**
  51.      * @var integer
  52.      * @ORM\Column(name="co_status", type="smallint", nullable=true)
  53.      */
  54.     private $coStatus;
  55.     /**
  56.      * @var integer
  57.      * @ORM\Column(name="co_payment_period", type="smallint", nullable=true)
  58.      */
  59.     private $coPaymentPeriod;
  60.     /**
  61.      * @var \App\Entity\User
  62.      * @ORM\ManyToOne(targetEntity="App\Entity\User")
  63.      * @ORM\JoinColumns({
  64.      *   @ORM\JoinColumn(name="co_user_creator", referencedColumnName="us_id", onDelete="CASCADE")
  65.      * })
  66.      */
  67.     private $coUserCreator;
  68.     /**
  69.      * @var \App\Entity\City
  70.      * @ORM\ManyToOne(targetEntity="App\Entity\City")
  71.      * @ORM\JoinColumns({
  72.      *   @ORM\JoinColumn(name="co_city_id", referencedColumnName="ci_id", nullable=true)
  73.      * })
  74.      */
  75.     private $city;
  76.     /**
  77.      * @var \App\Entity\Zipcode
  78.      * @ORM\ManyToOne(targetEntity="App\Entity\Zipcode")
  79.      * @ORM\JoinColumns({
  80.      *   @ORM\JoinColumn(name="al_zip_code_id", referencedColumnName="zc_id", nullable=true)
  81.      * })
  82.      */
  83.     private $zipcode;
  84.     /**
  85.      * @var string
  86.      * @ORM\Column(name="co_logo", type="string", length=255, nullable=true)
  87.      */
  88.     private $coLogo;
  89.     
  90.     /**
  91.      * @var integer
  92.      * @ORM\Column(name="co_is_kijho", type="smallint", nullable=true, options={"default":"0"})
  93.      */
  94.     private $coIsKijho 0;
  95.     /**
  96.      * @var boolean
  97.      * @ORM\Column(name="co_is_created_by_crm", type="boolean", nullable=true, options={"default":"false"})
  98.      */
  99.     private $coIsCreatedByCrm false;
  100.     /**
  101.      * @var boolean
  102.      * @ORM\Column(name="co_is_complete_by_crm", type="boolean", nullable=true, options={"default":"false"})
  103.      */
  104.     private $coIsCompleteByCrm false;
  105.     /**
  106.      * @var string
  107.      * @ORM\Column(name="co_previous_balance", type="decimal", precision=10, scale=2, nullable=true)
  108.      */
  109.     private $previousBalance;
  110.     /**
  111.      * @var boolean
  112.      * @ORM\Column(name="co_update_schedule_a_file", type="boolean", nullable=false, options={"default":"false"})
  113.      */
  114.     private $coUpdateScheduleAFile false;
  115.     /**
  116.      * @return integer
  117.      */
  118.     public function getId() {
  119.         return $this->id;
  120.     }
  121.     /**
  122.      * @return type
  123.      */
  124.     public function getPreviousBalance() {
  125.         return $this->previousBalance;
  126.     }
  127.     /**
  128.      * @param type $previousBalance
  129.      */
  130.     public function setPreviousBalance($previousBalance) {
  131.         $this->previousBalance $previousBalance;
  132.     }
  133.     /**
  134.      * @return type
  135.      */
  136.     public function getCoAddress() {
  137.         return $this->coAddress;
  138.     }
  139.     /**
  140.      * @param type $coAddress
  141.      */
  142.     public function setCoAddress($coAddress) {
  143.         $this->coAddress $coAddress;
  144.     }
  145.     /**
  146.      * @return type
  147.      */
  148.     public function getCoCompanyName() {
  149.         return $this->coCompanyName;
  150.     }
  151.     /**
  152.      * @return type
  153.      */
  154.     public function getCoCompanyIdentification() {
  155.         return $this->coCompanyIdentification;
  156.     }
  157.     /**
  158.      * @return type
  159.      */
  160.     public function getCoDateCreated() {
  161.         return $this->coDateCreated;
  162.     }
  163.     /**
  164.      * @return type
  165.      */
  166.     public function getCoUserCreator() {
  167.         return $this->coUserCreator;
  168.     }
  169.     /**
  170.      * @return type
  171.      */
  172.     public function getCity() {
  173.         return $this->city;
  174.     }
  175.     /**
  176.      * @return type
  177.      */
  178.     public function getCoStatus() {
  179.         return $this->coStatus;
  180.     }
  181.     /**
  182.      * @return type
  183.      */
  184.     public function getZipcode() {
  185.         return $this->zipcode;
  186.     }
  187.     /**
  188.      * @param type $coCompanyName
  189.      */
  190.     public function setCoCompanyName($coCompanyName) {
  191.         $this->coCompanyName $coCompanyName;
  192.     }
  193.     /**
  194.      * @param type $coCompanyIdentification
  195.      */
  196.     public function setCoCompanyIdentification($coCompanyIdentification) {
  197.         $this->coCompanyIdentification $coCompanyIdentification;
  198.     }
  199.     /**
  200.      * @param \DateTime $coDateCreated
  201.      */
  202.     public function setCoDateCreated(\DateTime $coDateCreated) {
  203.         $this->coDateCreated $coDateCreated;
  204.     }
  205.     /**
  206.      * @param \App\Entity\User $coUserCreator
  207.      */
  208.     public function setCoUserCreator(\App\Entity\User $coUserCreator) {
  209.         $this->coUserCreator $coUserCreator;
  210.     }
  211.     /**
  212.      * @param \App\Entity\City $coCity
  213.      */
  214.     public function setCity(\App\Entity\City $coCity) {
  215.         $this->city $coCity;
  216.     }
  217.     /**
  218.      * @param type $coStatus
  219.      */
  220.     public function setCoStatus($coStatus 1) {
  221.         $this->coStatus $coStatus;
  222.     }
  223.     /**
  224.      * @param \App\Entity\Zipcode $alZipCode
  225.      */
  226.     public function setZipcode(?\App\Entity\Zipcode $alZipCode null) {
  227.         $this->zipcode $alZipCode;
  228.     }
  229.     /**
  230.      * @return type
  231.      */
  232.     public function __toString() {
  233.         return "" $this->getCoCompanyName();
  234.     }
  235.     /**
  236.      * @return string
  237.      */
  238.     public function getTextStatus() {
  239.         $text '';
  240.         switch ($this->coStatus) {
  241.             case static::STATUS_ACTIVE$text 'Active';
  242.                 break;
  243.             case static::STATUS_INACTIVE$text 'Inactive';
  244.                 break;
  245.             default:
  246.                 $text 'Inactive';
  247.         }
  248.         return $text;
  249.     }
  250.     /**
  251.      * @return string
  252.      */ 
  253.     public function getCoLogo()
  254.     {
  255.         return $this->coLogo;
  256.     }
  257.     /**
  258.      * @param  string  $coLogo
  259.      */ 
  260.     public function setCoLogo($coLogo)
  261.     {
  262.         $this->coLogo $coLogo;
  263.     }
  264.     /**
  265.      * @return type
  266.      */
  267.     public function getCoIsKijho() {
  268.         return $this->coIsKijho;
  269.     }
  270.     /**
  271.      * @param type $coIsKijho
  272.      */
  273.     public function setCoIsKijho($coIsKijho) {
  274.         $this->coIsKijho $coIsKijho;
  275.     }
  276.     /**
  277.      * @return  boolean
  278.      */ 
  279.     public function getCoIsCreatedByCrm() {
  280.         return $this->coIsCreatedByCrm;
  281.     }
  282.     /**
  283.      * @param  boolean  $coIsCreatedByCrm
  284.      */ 
  285.     public function setCoIsCreatedByCrm($coIsCreatedByCrm) {
  286.         $this->coIsCreatedByCrm $coIsCreatedByCrm;
  287.     }
  288.     
  289.     /**
  290.      * @return  boolean
  291.      */ 
  292.     public function getCoIsCompleteByCrm() {
  293.         return $this->coIsCompleteByCrm;
  294.     }
  295.     /**
  296.      * @param  boolean  $coIsCompleteByCrm
  297.      */ 
  298.     public function setCoIsCompleteByCrm($coIsCompleteByCrm) {
  299.         $this->coIsCompleteByCrm $coIsCompleteByCrm;
  300.     }
  301.     
  302.     /**
  303.      * @return  boolean
  304.      */ 
  305.     public function getCoUpdateScheduleAFile() {
  306.         return $this->coUpdateScheduleAFile;
  307.     }
  308.     /**
  309.      * @param  boolean  $coUpdateScheduleAFile
  310.      */ 
  311.     public function setCoUpdateScheduleAFile($coUpdateScheduleAFile) {
  312.         $this->coUpdateScheduleAFile $coUpdateScheduleAFile;
  313.     }
  314.     /**
  315.      * Fucion generico para realizar busquedas de esta entidad
  316.      * @author Aealan Z <lrobledo@kijho.com> 29/07/2016
  317.      * @param type $alias
  318.      * @param type $search
  319.      * @return type
  320.      */
  321.     public static function filterSearchParameters($alias$search) {
  322.         $textParameters '';
  323.         $parameters = [];
  324.         $orderBy '';
  325.         if (isset($search ['coCompanyName']) && $search ['coCompanyName'] != '') {
  326.             $textParameters .= " AND " $alias ".coCompanyName LIKE :coCompanyName";
  327.             $parameters ['coCompanyName'] = "%" $search ['coCompanyName'] . "%";
  328.         }
  329.         if (isset($search ['coCompanyIdentification']) && $search ['coCompanyIdentification'] != '') {
  330.             $textParameters .= " AND " $alias ".coCompanyIdentification LIKE :coCompanyIdentification";
  331.             $parameters ['coCompanyIdentification'] = "%" $search ['coCompanyIdentification'] . "%";
  332.         }
  333.         if (isset($search ['coStatus']) && $search ['coStatus'] != '') {
  334.             $textParameters .= " AND " $alias ".coStatus = :coStatus";
  335.             $parameters ['coStatus'] = $search ['coStatus'];
  336.         }
  337.         if (isset($search['coUserCreator']) && !is_null($search['coUserCreator']) && $search['coUserCreator'] instanceof User) {
  338.             $textParameters .= " AND " $alias ".coUserCreator = :coUserCreator";
  339.             $parameters['coUserCreator'] = $search['coUserCreator']->getId();
  340.         }
  341.         // condiciones para que en la consulta aparezca la compañía del usuario tipo agent manager en sesión 
  342.         if (isset($search['userType']) && !is_null($search['userType']) && $search['userType'] == User::USER_AGENT_MANAGER) {
  343.             if (isset($search['myCompany']) && !is_null($search['myCompany']) && $search['myCompany'] != '') {
  344.                 $textParameters .= " OR " $alias ".id = :coMyCompany";
  345.                 $parameters['coMyCompany'] = $search['myCompany'];
  346.                 // este order by es para que la compañía del usuario aparezca de primera en el resultado de la consulta
  347.                 $orderBy " CASE WHEN {$alias}.id = {$search['myCompany']} THEN 0 ELSE 1 END, {$alias}.coCompanyName ASC";
  348.             }
  349.         }
  350.         return ['text' => $textParameters'parameters' => $parameters'orderBy' => $orderBy];
  351.     }
  352.     /**
  353.      * FilterOrderParameters retorna el adecaudo orderBy segun los parametros
  354.      * @author Aealan Z <lrobledo@kijho.com> 29/07/2016
  355.      * @param string $alias
  356.      * @param Array $order
  357.      * @return string
  358.      */
  359.     public static function filterOrderParameters($alias$order) {
  360.         $orderBy ' ORDER BY ' $alias '.coCompanyName ASC';
  361.         if (isset($order ['order_by_company_name']) && $order ['order_by_company_name'] != '') {
  362.             if ($order ['order_by_company_name'] % 2) {
  363.                 $orderBy " ORDER BY " $alias ".coCompanyName DESC";
  364.             } else {
  365.                 $orderBy " ORDER BY " $alias ".coCompanyName ASC";
  366.             }
  367.         } elseif (isset($order ['order_by_company_identification']) && $order ['order_by_company_identification'] != '') {
  368.             if ($order ['order_by_company_identification'] % 2) {
  369.                 $orderBy " ORDER BY " $alias ".coCompanyIdentification DESC";
  370.             } else {
  371.                 $orderBy " ORDER BY " $alias ".coCompanyIdentification ASC";
  372.             }
  373.         } elseif (isset($order ['order_by_company_status']) && $order ['order_by_company_status'] != '') {
  374.             if ($order ['order_by_company_status'] % 2) {
  375.                 $orderBy " ORDER BY " $alias ".coStatus DESC";
  376.             } else {
  377.                 $orderBy " ORDER BY " $alias ".coStatus ASC";
  378.             }
  379.             
  380.         }
  381.         return $orderBy;
  382.     }
  383.     /**
  384.      * Función para pasar a de tipo objeto-entidad a json
  385.      */
  386.     public function showEverything() {
  387.         return get_object_vars($this);
  388.     }
  389.     public function getCoPaymentPeriod()
  390.     {
  391.         return $this->coPaymentPeriod;
  392.     }
  393.     public function setCoPaymentPeriod($coPaymentPeriod)
  394.     {
  395.         $this->coPaymentPeriod $coPaymentPeriod;
  396.         return $this;
  397.     }
  398. }