1: <?php
2:
3:
4:
5:
6:
7: /**
8: * CommercialSellingAccount
9: *
10: * @Table(name="COMMERCIAL_SELLING_ACCOUNT")
11: * @Entity(repositoryClass="CommercialSellingAccountRepository")
12: * @HasLifecycleCallbacks
13: *
14: */
15: class CommercialSellingAccount
16: {
17: /**
18: * @var string $label
19: *
20: * @Column(name="label", type="string", length=45)
21: */
22: private $label;
23:
24: /**
25: * @var string $accountNumber
26: *
27: * @Column(name="account_number", type="string", length=15)
28: */
29: private $accountNumber;
30:
31: /**
32: * @var integer $id
33: *
34: * @Column(name="id", type="integer")
35: * @Id
36: * @GeneratedValue(strategy="IDENTITY")
37: */
38: private $id;
39:
40: /**
41: * @var CoreCompanies
42: *
43: * @ManyToOne(targetEntity="CoreCompanies")
44: * @JoinColumns({
45: * @JoinColumn(name="company_id", referencedColumnName="id")
46: * })
47: */
48: private $company;
49:
50:
51: /**
52: * Set label
53: *
54: * @param string $label
55: * @return CommercialSellingAccount
56: */
57: public function setLabel($label)
58: {
59: $this->label = $label;
60: return $this;
61: }
62:
63: /**
64: * Get label
65: *
66: * @return string
67: */
68: public function getLabel()
69: {
70: return $this->label;
71: }
72:
73: /**
74: * Set accountNumber
75: *
76: * @param string $accountNumber
77: * @return CommercialSellingAccount
78: */
79: public function setAccountNumber($accountNumber)
80: {
81: $this->accountNumber = $accountNumber;
82: return $this;
83: }
84:
85: /**
86: * Get accountNumber
87: *
88: * @return string
89: */
90: public function getAccountNumber()
91: {
92: return $this->accountNumber;
93: }
94:
95: /**
96: * Get id
97: *
98: * @return integer
99: */
100: public function getId()
101: {
102: return $this->id;
103: }
104:
105: /**
106: * Set company
107: *
108: * @param CoreCompanies $company
109: * @return CommercialSellingAccount
110: */
111: public function setCompany(\CoreCompanies $company = null)
112: {
113: $this->company = $company;
114: return $this;
115: }
116:
117: /**
118: * Get company
119: *
120: * @return CoreCompanies
121: */
122: public function getCompany()
123: {
124: return $this->company;
125: }
126:
127: /**
128: * @PrePersist
129: * @PreUpdate
130: */
131: public function prePersist() {
132: if($this->company == null) {
133: $this->company = \IgestisSecurity::init()->user->getCompany();
134: }
135: }
136: }
137:
138:
139: // ---------------------------------------------------------------------
140:
141: class CommercialSellingAccountRepository extends \Doctrine\ORM\EntityRepository {
142:
143: public function findAll() {
144: try {
145: $userCompany = \IgestisSecurity::init()->user->getCompany();
146: $qb = $this->_em->createQueryBuilder();
147: $qb->select("sa")
148: ->from("CommercialSellingAccount", "sa")
149: ->where("sa.company = :company")
150: ->setParameter("company", $userCompany);
151: }
152: catch (\Exception $e) {
153: throw $e;
154: }
155:
156: return $qb->getQuery()->getResult();
157:
158: }
159:
160: public function find($id, $lockMode = \Doctrine\DBAL\LockMode::NONE, $lockVersion = null) {
161: $result = parent::find($id, $lockMode, $lockVersion);
162: if(!$result || $result->getCompany()->getId() != \IgestisSecurity::init()->user->getCompany()->getId()) return null;
163: return $result;
164: }
165:
166: }