@@ -113,8 +113,9 @@ |
||
| 113 | 113 | |
| 114 | 114 | return true; |
| 115 | 115 | } catch (\Exception $e) { |
| 116 | - if ($this->manager->getConnection()->isTransactionActive()) |
|
| 117 | - $this->manager->getConnection()->rollBack(); |
|
| 116 | + if ($this->manager->getConnection()->isTransactionActive()) { |
|
| 117 | + $this->manager->getConnection()->rollBack(); |
|
| 118 | + } |
|
| 118 | 119 | |
| 119 | 120 | throw new \InvalidArgumentException($e->getMessage()); |
| 120 | 121 | } |
@@ -27,13 +27,13 @@ discard block |
||
| 27 | 27 | * |
| 28 | 28 | * @var Request |
| 29 | 29 | */ |
| 30 | - private $request = null; |
|
| 30 | + private $request = null; |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | 33 | |
| 34 | 34 | public function __construct(EntityManagerInterface $manager) |
| 35 | 35 | { |
| 36 | - $this->manager = $manager; |
|
| 36 | + $this->manager = $manager; |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | public function __invoke(People $data, Request $request): JsonResponse |
@@ -75,12 +75,12 @@ discard block |
||
| 75 | 75 | throw new \InvalidArgumentException('Document id is not defined'); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - $users = $this->manager->getRepository(User::class)->findBy(['people' => $person]); |
|
| 78 | + $users = $this->manager->getRepository(User::class)->findBy(['people' => $person]); |
|
| 79 | 79 | if (count($users) == 1) { |
| 80 | 80 | throw new \InvalidArgumentException('Deve existir pelo menos um usuário'); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - $user = $this->manager->getRepository(User::class)->findOneBy(['id' => $payload['id'], 'people' => $person]); |
|
| 83 | + $user = $this->manager->getRepository(User::class)->findOneBy(['id' => $payload['id'], 'people' => $person]); |
|
| 84 | 84 | if (!$user instanceof User) { |
| 85 | 85 | throw new \InvalidArgumentException('Person user was not found'); |
| 86 | 86 | } |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | |
| 44 | - public function getCompanyPeopleLinks(People $company, People $people, $linkType = null, $maxResults = null) |
|
| 44 | + public function getCompanyPeopleLinks(People $company, People $people, $linkType = null, $maxResults = null) |
|
| 45 | 45 | { |
| 46 | 46 | $queryBuilder = $this->getEntityManager()->createQueryBuilder(); |
| 47 | 47 | $queryBuilder->select('pl') |
@@ -51,8 +51,9 @@ |
||
| 51 | 51 | ->setParameter('company', $company->getId()) |
| 52 | 52 | ->setParameter('people', $people->getId()); |
| 53 | 53 | |
| 54 | - if ($linkType) |
|
| 55 | - $queryBuilder->setParameter('linkType', $linkType)->andWhere('pl.link_type = :linkType'); |
|
| 54 | + if ($linkType) { |
|
| 55 | + $queryBuilder->setParameter('linkType', $linkType)->andWhere('pl.link_type = :linkType'); |
|
| 56 | + } |
|
| 56 | 57 | |
| 57 | 58 | if ($maxResults) { |
| 58 | 59 | $queryBuilder->setMaxResults($maxResults); |
@@ -112,31 +112,31 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | case 'active': |
| 114 | 114 | |
| 115 | - $queryBuilder->innerJoin(Order::class, 'O' , 'WITH', 'O.client = myclients.id'); |
|
| 116 | - $queryBuilder->innerJoin(People::class, 'C' , 'WITH', 'C.id = O.provider'); |
|
| 115 | + $queryBuilder->innerJoin(Order::class, 'O', 'WITH', 'O.client = myclients.id'); |
|
| 116 | + $queryBuilder->innerJoin(People::class, 'C', 'WITH', 'C.id = O.provider'); |
|
| 117 | 117 | $queryBuilder->innerJoin(PeopleSalesman::class, 'kkk', 'WITH', 'kkk.company = C.id'); |
| 118 | - $queryBuilder->innerJoin(People::class, 'S' , 'WITH', 'S.id = kkk.salesman'); |
|
| 119 | - $queryBuilder->innerJoin(PeopleClient::class, 'PC' , 'WITH', 'PC.client = myclients.id AND PC.company_id = S.id'); |
|
| 118 | + $queryBuilder->innerJoin(People::class, 'S', 'WITH', 'S.id = kkk.salesman'); |
|
| 119 | + $queryBuilder->innerJoin(PeopleClient::class, 'PC', 'WITH', 'PC.client = myclients.id AND PC.company_id = S.id'); |
|
| 120 | 120 | $queryBuilder->andWhere('O.provider = :provider'); |
| 121 | 121 | $queryBuilder->andWhere('S.id IN (:my_companies)'); |
| 122 | 122 | $queryBuilder->andWhere('O.status NOT IN (:statuses)'); |
| 123 | 123 | $queryBuilder->andWhere('O.orderDate BETWEEN :from_date AND :to_date'); |
| 124 | - $queryBuilder->setParameter('provider' , $provider); |
|
| 125 | - $queryBuilder->setParameter('statuses' , $this->getEntityManager()->getRepository(Status::class)->findBy(['realStatus' => ['open','canceled']])); |
|
| 126 | - $queryBuilder->setParameter('from_date' , $fromDate); |
|
| 127 | - $queryBuilder->setParameter('to_date' , $toDate); |
|
| 124 | + $queryBuilder->setParameter('provider', $provider); |
|
| 125 | + $queryBuilder->setParameter('statuses', $this->getEntityManager()->getRepository(Status::class)->findBy(['realStatus' => ['open', 'canceled']])); |
|
| 126 | + $queryBuilder->setParameter('from_date', $fromDate); |
|
| 127 | + $queryBuilder->setParameter('to_date', $toDate); |
|
| 128 | 128 | $queryBuilder->setParameter('my_companies', $this->getMyCompanies($salesman)); |
| 129 | 129 | |
| 130 | 130 | break; |
| 131 | 131 | |
| 132 | 132 | case 'inactive': |
| 133 | 133 | |
| 134 | - $queryBuilder->innerJoin(Order::class, 'O' , 'WITH', 'O.client = myclients.id'); |
|
| 135 | - $queryBuilder->innerJoin(People::class, 'C' , 'WITH', 'C.id = O.provider'); |
|
| 134 | + $queryBuilder->innerJoin(Order::class, 'O', 'WITH', 'O.client = myclients.id'); |
|
| 135 | + $queryBuilder->innerJoin(People::class, 'C', 'WITH', 'C.id = O.provider'); |
|
| 136 | 136 | $queryBuilder->innerJoin(PeopleSalesman::class, 'kkk', 'WITH', 'kkk.company = C.id'); |
| 137 | - $queryBuilder->innerJoin(People::class, 'S' , 'WITH', 'S.id = kkk.salesman'); |
|
| 138 | - $queryBuilder->innerJoin(PeopleClient::class, 'PC' , 'WITH', 'PC.client = myclients.id AND PC.company_id = S.id'); |
|
| 139 | - $queryBuilder->leftJoin (Order::class, 'jj' , 'WITH', 'jj.client = myclients.id |
|
| 137 | + $queryBuilder->innerJoin(People::class, 'S', 'WITH', 'S.id = kkk.salesman'); |
|
| 138 | + $queryBuilder->innerJoin(PeopleClient::class, 'PC', 'WITH', 'PC.client = myclients.id AND PC.company_id = S.id'); |
|
| 139 | + $queryBuilder->leftJoin(Order::class, 'jj', 'WITH', 'jj.client = myclients.id |
|
| 140 | 140 | AND (jj.status NOT IN (:statuses) OR jj.id IS NULL) |
| 141 | 141 | AND ((jj.orderDate BETWEEN :from_date AND :to_date) OR jj.id IS NULL) |
| 142 | 142 | AND (jj.provider = :provider OR jj.id IS NULL)'); |
@@ -147,23 +147,23 @@ discard block |
||
| 147 | 147 | $queryBuilder->groupBy('myclients.id'); |
| 148 | 148 | $queryBuilder->having('COUNT(jj.id) > :count'); |
| 149 | 149 | $queryBuilder->andHaving('COUNT(O.id) = :count'); |
| 150 | - $queryBuilder->setParameter('provider' , $provider); |
|
| 151 | - $queryBuilder->setParameter('statuses' , $this->getEntityManager()->getRepository(Status::class)->findBy(['realStatus' => ['open','canceled']])); |
|
| 150 | + $queryBuilder->setParameter('provider', $provider); |
|
| 151 | + $queryBuilder->setParameter('statuses', $this->getEntityManager()->getRepository(Status::class)->findBy(['realStatus' => ['open', 'canceled']])); |
|
| 152 | 152 | $queryBuilder->setParameter('from_date', $fromDate); |
| 153 | - $queryBuilder->setParameter('to_date' , $toDate); |
|
| 154 | - $queryBuilder->setParameter('count' , 0); |
|
| 153 | + $queryBuilder->setParameter('to_date', $toDate); |
|
| 154 | + $queryBuilder->setParameter('count', 0); |
|
| 155 | 155 | $queryBuilder->setParameter('my_companies', $this->getMyCompanies($salesman)); |
| 156 | 156 | |
| 157 | 157 | break; |
| 158 | 158 | |
| 159 | 159 | case 'prospect': |
| 160 | 160 | |
| 161 | - $queryBuilder->innerJoin(Order::class, 'O' , 'WITH', 'O.client = myclients.id'); |
|
| 162 | - $queryBuilder->innerJoin(People::class, 'C' , 'WITH', 'C.id = O.provider'); |
|
| 161 | + $queryBuilder->innerJoin(Order::class, 'O', 'WITH', 'O.client = myclients.id'); |
|
| 162 | + $queryBuilder->innerJoin(People::class, 'C', 'WITH', 'C.id = O.provider'); |
|
| 163 | 163 | $queryBuilder->innerJoin(PeopleSalesman::class, 'PS', 'WITH', 'PS.company = C.id'); |
| 164 | - $queryBuilder->innerJoin(People::class, 'S' , 'WITH', 'S.id = PS.salesman'); |
|
| 165 | - $queryBuilder->innerJoin(PeopleClient::class, 'PC', 'WITH', 'PC.client = myclients.id AND PC.company_id = S.id'); |
|
| 166 | - $queryBuilder->leftJoin (Order::class, 'jj' , 'WITH', 'jj.client = myclients.id |
|
| 164 | + $queryBuilder->innerJoin(People::class, 'S', 'WITH', 'S.id = PS.salesman'); |
|
| 165 | + $queryBuilder->innerJoin(PeopleClient::class, 'PC', 'WITH', 'PC.client = myclients.id AND PC.company_id = S.id'); |
|
| 166 | + $queryBuilder->leftJoin(Order::class, 'jj', 'WITH', 'jj.client = myclients.id |
|
| 167 | 167 | AND (jj.status NOT IN (:statuses) OR jj.id IS NULL) |
| 168 | 168 | AND (jj.provider = :provider OR jj.id IS NULL)'); |
| 169 | 169 | $queryBuilder->andWhere('O.provider = :provider'); |
@@ -173,19 +173,19 @@ discard block |
||
| 173 | 173 | $queryBuilder->having('COUNT(jj.id) = :count'); |
| 174 | 174 | |
| 175 | 175 | $queryBuilder->setParameter('provider', $provider); |
| 176 | - $queryBuilder->setParameter('statuses', $this->getEntityManager()->getRepository(Status::class)->findBy(['realStatus' => ['open','canceled']])); |
|
| 177 | - $queryBuilder->setParameter('count' , 0); |
|
| 176 | + $queryBuilder->setParameter('statuses', $this->getEntityManager()->getRepository(Status::class)->findBy(['realStatus' => ['open', 'canceled']])); |
|
| 177 | + $queryBuilder->setParameter('count', 0); |
|
| 178 | 178 | $queryBuilder->setParameter('my_companies', $this->getMyCompanies($salesman)); |
| 179 | 179 | |
| 180 | 180 | break; |
| 181 | 181 | |
| 182 | 182 | case 'new': |
| 183 | 183 | |
| 184 | - $queryBuilder->innerJoin(Order::class, 'O' , 'WITH', 'O.client = myclients.id'); |
|
| 185 | - $queryBuilder->innerJoin(People::class, 'C' , 'WITH', 'C.id = O.provider'); |
|
| 184 | + $queryBuilder->innerJoin(Order::class, 'O', 'WITH', 'O.client = myclients.id'); |
|
| 185 | + $queryBuilder->innerJoin(People::class, 'C', 'WITH', 'C.id = O.provider'); |
|
| 186 | 186 | $queryBuilder->innerJoin(PeopleSalesman::class, 'kkk', 'WITH', 'kkk.company = C.id'); |
| 187 | - $queryBuilder->innerJoin(People::class, 'S' , 'WITH', 'S.id = kkk.salesman'); |
|
| 188 | - $queryBuilder->innerJoin(PeopleClient::class, 'PC' , 'WITH', 'PC.client = myclients.id AND PC.company_id = S.id'); |
|
| 187 | + $queryBuilder->innerJoin(People::class, 'S', 'WITH', 'S.id = kkk.salesman'); |
|
| 188 | + $queryBuilder->innerJoin(PeopleClient::class, 'PC', 'WITH', 'PC.client = myclients.id AND PC.company_id = S.id'); |
|
| 189 | 189 | |
| 190 | 190 | $queryBuilder->andWhere('O.provider = :provider'); |
| 191 | 191 | $queryBuilder->andWhere('S.id IN (:my_companies)'); |
@@ -193,10 +193,10 @@ discard block |
||
| 193 | 193 | $queryBuilder->andWhere('O.orderDate BETWEEN :from_date AND :to_date'); |
| 194 | 194 | $queryBuilder->andWhere('myclients.registerDate BETWEEN :from_date AND :to_date'); |
| 195 | 195 | |
| 196 | - $queryBuilder->setParameter('provider' , $provider); |
|
| 197 | - $queryBuilder->setParameter('statuses' , $this->getEntityManager()->getRepository(Status::class)->findBy(['realStatus' => ['open','canceled']])); |
|
| 198 | - $queryBuilder->setParameter('from_date' , $fromDate); |
|
| 199 | - $queryBuilder->setParameter('to_date' , $toDate); |
|
| 196 | + $queryBuilder->setParameter('provider', $provider); |
|
| 197 | + $queryBuilder->setParameter('statuses', $this->getEntityManager()->getRepository(Status::class)->findBy(['realStatus' => ['open', 'canceled']])); |
|
| 198 | + $queryBuilder->setParameter('from_date', $fromDate); |
|
| 199 | + $queryBuilder->setParameter('to_date', $toDate); |
|
| 200 | 200 | $queryBuilder->setParameter('my_companies', $this->getMyCompanies($salesman)); |
| 201 | 201 | |
| 202 | 202 | break; |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - $peopleemployee = $this->em->getRepository(PeopleLink::class)->findOneBy(['company' => $company, 'employee' => $userPeople]); |
|
| 133 | + $peopleemployee = $this->em->getRepository(PeopleLink::class)->findOneBy(['company' => $company, 'employee' => $userPeople]); |
|
| 134 | 134 | |
| 135 | 135 | $permissions[$company->getId()][] = 'salesman'; |
| 136 | 136 | $myCompanies[$company->getId()] = [ |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | $myCompanies[$key]['permission'] = array_values($permission); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - usort($myCompanies, function ($a, $b) { |
|
| 161 | + usort($myCompanies, function($a, $b) { |
|
| 162 | 162 | |
| 163 | 163 | if ($a['alias'] == $b['alias']) { |
| 164 | 164 | return 0; |
@@ -204,11 +204,11 @@ discard block |
||
| 204 | 204 | $p_m[$package_module->getId()]['module'] = $package_module->getModule()->getName(); |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - $packages[$people_package->getId()]['id'] = $people_package->getId(); |
|
| 208 | - $packages[$people_package->getId()]['package']['id'] = $package->getId(); |
|
| 209 | - $packages[$people_package->getId()]['package']['name'] = $package->getName(); |
|
| 210 | - $packages[$people_package->getId()]['package']['active'] = $package->isActive() ? true : false; |
|
| 211 | - $packages[$people_package->getId()]['package']['modules'] = $p_m; |
|
| 207 | + $packages[$people_package->getId()]['id'] = $people_package->getId(); |
|
| 208 | + $packages[$people_package->getId()]['package']['id'] = $package->getId(); |
|
| 209 | + $packages[$people_package->getId()]['package']['name'] = $package->getName(); |
|
| 210 | + $packages[$people_package->getId()]['package']['active'] = $package->isActive() ? true : false; |
|
| 211 | + $packages[$people_package->getId()]['package']['modules'] = $p_m; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | return $packages; |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | /** |
| 244 | 244 | * @var \ControleOnline\Entity\Document $document |
| 245 | 245 | */ |
| 246 | - $documents = $documents->filter(function ($document) { |
|
| 246 | + $documents = $documents->filter(function($document) { |
|
| 247 | 247 | return $document->getDocumentType()->getDocumentType() == 'CNPJ'; |
| 248 | 248 | }); |
| 249 | 249 | |
@@ -88,7 +88,7 @@ |
||
| 88 | 88 | 'background' => $this->domainService->getPeopleDomain()->getTheme()->getBackground() ? [ |
| 89 | 89 | 'id' => $this->domainService->getPeopleDomain()->getTheme()->getBackground(), |
| 90 | 90 | 'domain' => $this->domainService->getMainDomain(), |
| 91 | - 'url' => '/files/' . $this->domainService->getPeopleDomain()->getTheme()->getBackground() . '/download' |
|
| 91 | + 'url' => '/files/'.$this->domainService->getPeopleDomain()->getTheme()->getBackground().'/download' |
|
| 92 | 92 | ] : null, |
| 93 | 93 | ]; |
| 94 | 94 | } |
@@ -111,7 +111,7 @@ |
||
| 111 | 111 | if (self::$mainCompany) return self::$mainCompany; |
| 112 | 112 | |
| 113 | 113 | $peopleDomain = $this->domainService->getPeopleDomain(); |
| 114 | - self::$mainCompany = $peopleDomain->getPeople(); |
|
| 114 | + self::$mainCompany = $peopleDomain->getPeople(); |
|
| 115 | 115 | |
| 116 | 116 | return self::$mainCompany; |
| 117 | 117 | } |
@@ -34,7 +34,9 @@ discard block |
||
| 34 | 34 | $isSalesman = false; |
| 35 | 35 | |
| 36 | 36 | $isSalesman = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $people, 'salesman', 1); |
| 37 | - if ($isSalesman) return true; |
|
| 37 | + if ($isSalesman) { |
|
| 38 | + return true; |
|
| 39 | + } |
|
| 38 | 40 | |
| 39 | 41 | $getPeopleCompanies = $this->manager->getRepository(PeopleLink::class)->findBy([ |
| 40 | 42 | 'people' => $people, |
@@ -45,7 +47,9 @@ discard block |
||
| 45 | 47 | */ |
| 46 | 48 | foreach ($getPeopleCompanies as $peopleCompany) { |
| 47 | 49 | $isSalesman = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $peopleCompany->getCompany(), 'salesman', 1); |
| 48 | - if ($isSalesman) return true; |
|
| 50 | + if ($isSalesman) { |
|
| 51 | + return true; |
|
| 52 | + } |
|
| 49 | 53 | } |
| 50 | 54 | return $isSalesman; |
| 51 | 55 | } |
@@ -57,8 +61,9 @@ discard block |
||
| 57 | 61 | $mainCompany = $this->getMainCompany(); |
| 58 | 62 | |
| 59 | 63 | $isSuper = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $people, 'employee', 1); |
| 60 | - if ($isSuper) |
|
| 61 | - $peopleRole[] = 'super'; |
|
| 64 | + if ($isSuper) { |
|
| 65 | + $peopleRole[] = 'super'; |
|
| 66 | + } |
|
| 62 | 67 | |
| 63 | 68 | |
| 64 | 69 | |
@@ -69,13 +74,15 @@ discard block |
||
| 69 | 74 | } |
| 70 | 75 | |
| 71 | 76 | $isClient = $this->manager->getRepository(People::class)->getCompanyPeopleLinks($mainCompany, $people, 'client', 1); |
| 72 | - if ($isClient) |
|
| 73 | - $peopleRole[] = 'client'; |
|
| 77 | + if ($isClient) { |
|
| 78 | + $peopleRole[] = 'client'; |
|
| 79 | + } |
|
| 74 | 80 | |
| 75 | 81 | |
| 76 | 82 | $isSalesman = $this->isSalesman($people); |
| 77 | - if ($isSalesman) |
|
| 78 | - $peopleRole[] = 'salesman'; |
|
| 83 | + if ($isSalesman) { |
|
| 84 | + $peopleRole[] = 'salesman'; |
|
| 85 | + } |
|
| 79 | 86 | |
| 80 | 87 | |
| 81 | 88 | return array_values(array_unique(empty($peopleRole) ? ['guest'] : $peopleRole)); |
@@ -89,7 +96,9 @@ discard block |
||
| 89 | 96 | public function getMainCompany(): People |
| 90 | 97 | { |
| 91 | 98 | |
| 92 | - if (self::$mainCompany) return self::$mainCompany; |
|
| 99 | + if (self::$mainCompany) { |
|
| 100 | + return self::$mainCompany; |
|
| 101 | + } |
|
| 93 | 102 | |
| 94 | 103 | $peopleDomain = $this->domainService->getPeopleDomain(); |
| 95 | 104 | self::$mainCompany = $peopleDomain->getPeople(); |
@@ -698,7 +698,7 @@ |
||
| 698 | 698 | |
| 699 | 699 | public function getOneDocument(): ?Document |
| 700 | 700 | { |
| 701 | - $documents = $this->getDocument()->filter(function ($peopleDocument) { |
|
| 701 | + $documents = $this->getDocument()->filter(function($peopleDocument) { |
|
| 702 | 702 | if ($peopleDocument->getPeople()->getPeopleType() == 'F') { |
| 703 | 703 | return $peopleDocument->getDocumentType()->getDocumentType() == 'CPF'; |
| 704 | 704 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | private Security $security, |
| 28 | 28 | private RequestStack $requestStack, |
| 29 | 29 | ) { |
| 30 | - $this->request = $requestStack->getCurrentRequest(); |
|
| 30 | + $this->request = $requestStack->getCurrentRequest(); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | public function prePersist(People $people) |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | $phone = $this->getPhone($phone_number['ddd'], $phone_number['phone']); |
| 79 | 79 | if ($phone && $phone->getPeople()) { |
| 80 | 80 | if ($phone->getPeople()->getId() != $people->getId()) |
| 81 | - throw new Exception("Phone is in use by people " . $people->getId(), 1); |
|
| 81 | + throw new Exception("Phone is in use by people ".$people->getId(), 1); |
|
| 82 | 82 | } else { |
| 83 | 83 | $phone = new Phone(); |
| 84 | 84 | $phone->setDdd($phone_number['ddd']); |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | $document = $this->getDocument($document_number, $document_type); |
| 96 | 96 | if ($document) { |
| 97 | 97 | if ($document->getPeople()->getId() != $people->getId()) |
| 98 | - throw new Exception("Document is in use by people " . $people->getId(), 1); |
|
| 98 | + throw new Exception("Document is in use by people ".$people->getId(), 1); |
|
| 99 | 99 | } else { |
| 100 | 100 | $document = new Document(); |
| 101 | 101 | $document->setDocument($document_number); |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | $email = $this->getEmail($email_str); |
| 114 | 114 | if ($email && $email->getPeople()) { |
| 115 | 115 | if ($email->getPeople()->getId() != $people->getId()) |
| 116 | - throw new Exception("Email is in use by people " . $people->getId(), 1); |
|
| 116 | + throw new Exception("Email is in use by people ".$people->getId(), 1); |
|
| 117 | 117 | } else { |
| 118 | 118 | $email = new Email(); |
| 119 | 119 | $email->setEmail($email_str); |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | public function discoveryDocumentType(string $document_type): DocumentType |
| 140 | 140 | { |
| 141 | - $documentType = $this->manager->getRepository(DocumentType::class)->findOneBy(['documentType' => $document_type]); |
|
| 141 | + $documentType = $this->manager->getRepository(DocumentType::class)->findOneBy(['documentType' => $document_type]); |
|
| 142 | 142 | |
| 143 | 143 | if (!$documentType) { |
| 144 | 144 | $documentType = new DocumentType(); |
@@ -214,29 +214,29 @@ discard block |
||
| 214 | 214 | public function checkLink(QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, $rootAlias = null): void |
| 215 | 215 | { |
| 216 | 216 | |
| 217 | - $link = $this->request->query->get('link', null); |
|
| 217 | + $link = $this->request->query->get('link', null); |
|
| 218 | 218 | $company = $this->request->query->get('company', null); |
| 219 | 219 | $link_type = $this->request->query->get('link_type', null); |
| 220 | 220 | |
| 221 | 221 | if ($link_type) { |
| 222 | - $queryBuilder->join(sprintf('%s.' . ($link ? 'company' : 'link'), $rootAlias), 'PeopleLink'); |
|
| 222 | + $queryBuilder->join(sprintf('%s.'.($link ? 'company' : 'link'), $rootAlias), 'PeopleLink'); |
|
| 223 | 223 | $queryBuilder->andWhere('PeopleLink.link_type IN(:link_type)'); |
| 224 | 224 | $queryBuilder->setParameter('link_type', $link_type); |
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | if ($company || $link) { |
| 228 | - $queryBuilder->andWhere('PeopleLink.' . ($link ? 'people' : 'company') . ' IN(:people)'); |
|
| 228 | + $queryBuilder->andWhere('PeopleLink.'.($link ? 'people' : 'company').' IN(:people)'); |
|
| 229 | 229 | $queryBuilder->setParameter('people', preg_replace("/[^0-9]/", "", ($link ?: $company))); |
| 230 | 230 | } |
| 231 | 231 | } |
| 232 | 232 | public function checkCompany($type, QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, $rootAlias = null): void |
| 233 | 233 | { |
| 234 | - $companies = $this->getMyCompanies(); |
|
| 235 | - $queryBuilder->andWhere(sprintf('%s.' . $type . ' IN(:companies)', $rootAlias, $rootAlias)); |
|
| 234 | + $companies = $this->getMyCompanies(); |
|
| 235 | + $queryBuilder->andWhere(sprintf('%s.'.$type.' IN(:companies)', $rootAlias, $rootAlias)); |
|
| 236 | 236 | $queryBuilder->setParameter('companies', $companies); |
| 237 | 237 | |
| 238 | 238 | if ($payer = $this->request->query->get('company', null)) { |
| 239 | - $queryBuilder->andWhere(sprintf('%s.' . $type . ' IN(:people)', $rootAlias)); |
|
| 239 | + $queryBuilder->andWhere(sprintf('%s.'.$type.' IN(:people)', $rootAlias)); |
|
| 240 | 240 | $queryBuilder->setParameter('people', preg_replace("/[^0-9]/", "", $payer)); |
| 241 | 241 | } |
| 242 | 242 | } |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | */ |
| 249 | 249 | $token = $this->security->getToken(); |
| 250 | 250 | if (!$token) return []; |
| 251 | - $currentUser = $token->getUser(); |
|
| 251 | + $currentUser = $token->getUser(); |
|
| 252 | 252 | $companies = []; |
| 253 | 253 | if (!$currentUser) return []; |
| 254 | 254 | |
@@ -45,14 +45,17 @@ discard block |
||
| 45 | 45 | public function discoveryPeople(?string $document = null, ?string $email = null, ?array $phone = [], ?string $name = null, ?string $peopleType = null): People |
| 46 | 46 | { |
| 47 | 47 | |
| 48 | - if (!empty($document)) |
|
| 49 | - $people = $this->getDocument($document)?->getPeople(); |
|
| 48 | + if (!empty($document)) { |
|
| 49 | + $people = $this->getDocument($document)?->getPeople(); |
|
| 50 | + } |
|
| 50 | 51 | |
| 51 | - if (!$people && !empty($email)) |
|
| 52 | - $people = $this->getEmail($email)?->getPeople(); |
|
| 52 | + if (!$people && !empty($email)) { |
|
| 53 | + $people = $this->getEmail($email)?->getPeople(); |
|
| 54 | + } |
|
| 53 | 55 | |
| 54 | - if (!$people && !empty($phone)) |
|
| 55 | - $people = $this->getPhone($phone['ddd'], $phone['phone'])?->getPeople(); |
|
| 56 | + if (!$people && !empty($phone)) { |
|
| 57 | + $people = $this->getPhone($phone['ddd'], $phone['phone'])?->getPeople(); |
|
| 58 | + } |
|
| 56 | 59 | |
| 57 | 60 | if (!$people) { |
| 58 | 61 | $people = new People(); |
@@ -63,12 +66,15 @@ discard block |
||
| 63 | 66 | $this->manager->flush(); |
| 64 | 67 | } |
| 65 | 68 | |
| 66 | - if ($document) |
|
| 67 | - $this->addDocument($people, $document); |
|
| 68 | - if ($email) |
|
| 69 | - $this->addEmail($people, $email); |
|
| 70 | - if ($phone) |
|
| 71 | - $this->addPhone($people, $phone); |
|
| 69 | + if ($document) { |
|
| 70 | + $this->addDocument($people, $document); |
|
| 71 | + } |
|
| 72 | + if ($email) { |
|
| 73 | + $this->addEmail($people, $email); |
|
| 74 | + } |
|
| 75 | + if ($phone) { |
|
| 76 | + $this->addPhone($people, $phone); |
|
| 77 | + } |
|
| 72 | 78 | |
| 73 | 79 | |
| 74 | 80 | return $people; |
@@ -78,8 +84,9 @@ discard block |
||
| 78 | 84 | { |
| 79 | 85 | $phone = $this->getPhone($phone_number['ddd'], $phone_number['phone']); |
| 80 | 86 | if ($phone && $phone->getPeople()) { |
| 81 | - if ($phone->getPeople()->getId() != $people->getId()) |
|
| 82 | - throw new Exception("Phone is in use by people " . $people->getId(), 1); |
|
| 87 | + if ($phone->getPeople()->getId() != $people->getId()) { |
|
| 88 | + throw new Exception("Phone is in use by people " . $people->getId(), 1); |
|
| 89 | + } |
|
| 83 | 90 | } else { |
| 84 | 91 | $phone = new Phone(); |
| 85 | 92 | $phone->setDdd($phone_number['ddd']); |
@@ -95,8 +102,9 @@ discard block |
||
| 95 | 102 | { |
| 96 | 103 | $document = $this->getDocument($document_number, $document_type); |
| 97 | 104 | if ($document) { |
| 98 | - if ($document->getPeople()->getId() != $people->getId()) |
|
| 99 | - throw new Exception("Document is in use by people " . $people->getId(), 1); |
|
| 105 | + if ($document->getPeople()->getId() != $people->getId()) { |
|
| 106 | + throw new Exception("Document is in use by people " . $people->getId(), 1); |
|
| 107 | + } |
|
| 100 | 108 | } else { |
| 101 | 109 | $document = new Document(); |
| 102 | 110 | $document->setDocument($document_number); |
@@ -113,8 +121,9 @@ discard block |
||
| 113 | 121 | { |
| 114 | 122 | $email = $this->getEmail($email_str); |
| 115 | 123 | if ($email && $email->getPeople()) { |
| 116 | - if ($email->getPeople()->getId() != $people->getId()) |
|
| 117 | - throw new Exception("Email is in use by people " . $people->getId(), 1); |
|
| 124 | + if ($email->getPeople()->getId() != $people->getId()) { |
|
| 125 | + throw new Exception("Email is in use by people " . $people->getId(), 1); |
|
| 126 | + } |
|
| 118 | 127 | } else { |
| 119 | 128 | $email = new Email(); |
| 120 | 129 | $email->setEmail($email_str); |
@@ -153,8 +162,9 @@ discard block |
||
| 153 | 162 | |
| 154 | 163 | public function getDocument(string $document_number, ?string $document_type = null): ?Document |
| 155 | 164 | { |
| 156 | - if (!$document_type) |
|
| 157 | - $document_type = $this->getDocumentTypeByDocumentLen($document_number); |
|
| 165 | + if (!$document_type) { |
|
| 166 | + $document_type = $this->getDocumentTypeByDocumentLen($document_number); |
|
| 167 | + } |
|
| 158 | 168 | return $this->manager->getRepository(Document::class)->findOneBy([ |
| 159 | 169 | 'document' => $document_number, |
| 160 | 170 | 'documentType' => |
@@ -175,18 +185,21 @@ discard block |
||
| 175 | 185 | public function postPersist(People $people) |
| 176 | 186 | { |
| 177 | 187 | $request = $this->requestStack->getCurrentRequest(); |
| 178 | - if (!$request) return; |
|
| 188 | + if (!$request) { |
|
| 189 | + return; |
|
| 190 | + } |
|
| 179 | 191 | $payload = json_decode($request->getContent()); |
| 180 | 192 | if (isset($payload->link_type)) { |
| 181 | 193 | $company = $this->manager->getRepository(People::class)->find(preg_replace('/\D/', '', $payload->company)); |
| 182 | - if ($company) |
|
| 183 | - $this->addLink($company, $people, $payload->link_type); |
|
| 184 | - else { |
|
| 194 | + if ($company) { |
|
| 195 | + $this->addLink($company, $people, $payload->link_type); |
|
| 196 | + } else { |
|
| 185 | 197 | $link = $this->manager->getRepository(People::class)->find(preg_replace('/\D/', '', $payload->link)); |
| 186 | 198 | if ($payload->link_type == 'employee' && $link) { |
| 187 | 199 | $this->addLink($people, $link, $payload->link_type); |
| 188 | - if ($payload->people_document) |
|
| 189 | - $this->addDocument($people, $payload->people_document); |
|
| 200 | + if ($payload->people_document) { |
|
| 201 | + $this->addDocument($people, $payload->people_document); |
|
| 202 | + } |
|
| 190 | 203 | } |
| 191 | 204 | } |
| 192 | 205 | } |
@@ -201,8 +214,9 @@ discard block |
||
| 201 | 214 | 'link_type' => $link_type |
| 202 | 215 | ]); |
| 203 | 216 | |
| 204 | - if (!$peopleLink) |
|
| 205 | - $peopleLink = new PeopleLink(); |
|
| 217 | + if (!$peopleLink) { |
|
| 218 | + $peopleLink = new PeopleLink(); |
|
| 219 | + } |
|
| 206 | 220 | |
| 207 | 221 | $peopleLink->setCompany($company); |
| 208 | 222 | $peopleLink->setPeople($people); |
@@ -254,10 +268,14 @@ discard block |
||
| 254 | 268 | * @var \ControleOnline\Entity\User $currentUser |
| 255 | 269 | */ |
| 256 | 270 | $token = $this->security->getToken(); |
| 257 | - if (!$token) return []; |
|
| 271 | + if (!$token) { |
|
| 272 | + return []; |
|
| 273 | + } |
|
| 258 | 274 | $currentUser = $token->getUser(); |
| 259 | 275 | $companies = []; |
| 260 | - if (!$currentUser) return []; |
|
| 276 | + if (!$currentUser) { |
|
| 277 | + return []; |
|
| 278 | + } |
|
| 261 | 279 | |
| 262 | 280 | if (!$currentUser->getPeople()->getLink()->isEmpty()) { |
| 263 | 281 | foreach ($currentUser->getPeople()->getLink() as $company) { |