diff --git a/hesabixCore/src/Controller/PersonsController.php b/hesabixCore/src/Controller/PersonsController.php index 92d6ed1..ed34b93 100644 --- a/hesabixCore/src/Controller/PersonsController.php +++ b/hesabixCore/src/Controller/PersonsController.php @@ -33,18 +33,19 @@ class PersonsController extends AbstractController * @param int $length number of characters in the generated string * @return string a new string is created with random characters of the desired length */ - private function RandomString($length = 32) { - return substr(str_shuffle(str_repeat($x='23456789ABCDEFGHJKLMNPQRSTUVWXYZ', ceil($length/strlen($x)) )),1,$length); + private function RandomString($length = 32) + { + return substr(str_shuffle(str_repeat($x = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length); } - /** + /** * @throws \ReflectionException */ #[Route('/api/person/types/get', name: 'app_persons_types_get')] - public function app_persons_types_get(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse + public function app_persons_types_get(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { $acc = $access->hasRole('person'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $items = $entityManager->getRepository(PersonType::class)->findAll(); return $this->json(Explore::ExplorePersonTypes($items)); @@ -54,23 +55,23 @@ class PersonsController extends AbstractController * @throws \ReflectionException */ #[Route('/api/person/info/{code}', name: 'app_persons_info')] - public function app_persons_info($code,Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse + public function app_persons_info($code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { $acc = $access->hasRole('person'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $person = $entityManager->getRepository(Person::class)->findOneBy([ - 'bid'=>$acc['bid'], - 'code'=>$code + 'bid' => $acc['bid'], + 'code' => $code ]); $types = $entityManager->getRepository(PersonType::class)->findAll(); - $response = Explore::ExplorePerson($person,$types); + $response = Explore::ExplorePerson($person, $types); $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ - 'person'=>$person + 'person' => $person ]); $bs = 0; $bd = 0; - foreach ($rows as $row){ + foreach ($rows as $row) { $bs += $row->getBs(); $bd += $row->getBd(); } @@ -80,90 +81,89 @@ class PersonsController extends AbstractController return $this->json($response); } #[Route('/api/person/mod/{code}', name: 'app_persons_mod')] - public function app_persons_mod(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse + public function app_persons_mod(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse { $acc = $access->hasRole('person'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $params = []; if ($content = $request->getContent()) { $params = json_decode($content, true); } - if(!array_key_exists('nikename',$params)) - return $this->json(['result'=>-1]); - if(count_chars(trim($params['nikename'])) == 0) - return $this->json(['result'=>3]); - if($code == 0){ + if (!array_key_exists('nikename', $params)) + return $this->json(['result' => -1]); + if (count_chars(trim($params['nikename'])) == 0) + return $this->json(['result' => 3]); + if ($code == 0) { $person = $entityManager->getRepository(Person::class)->findOneBy([ - 'nikename'=>$params['nikename'], - 'bid' =>$acc['bid'] + 'nikename' => $params['nikename'], + 'bid' => $acc['bid'] ]); //check exist before - if($person) - return $this->json(['result'=>2]); + if ($person) + return $this->json(['result' => 2]); $person = new Person(); - $person->setCode($provider->getAccountingCode($request->headers->get('activeBid'),'person')); - } - else{ + $person->setCode($provider->getAccountingCode($request->headers->get('activeBid'), 'person')); + } else { $person = $entityManager->getRepository(Person::class)->findOneBy([ - 'bid'=>$acc['bid'], - 'code'=>$code + 'bid' => $acc['bid'], + 'code' => $code ]); - if(!$person) + if (!$person) throw $this->createNotFoundException(); } $person->setBid($acc['bid']); $person->setNikename($params['nikename']); - if(array_key_exists('name',$params)) + if (array_key_exists('name', $params)) $person->setName($params['name']); - if(array_key_exists('birthday',$params)) + if (array_key_exists('birthday', $params)) $person->setBirthday($params['birthday']); - if(array_key_exists('tel',$params)) + if (array_key_exists('tel', $params)) $person->setTel($params['tel']); - if(array_key_exists('speedAccess',$params)) + if (array_key_exists('speedAccess', $params)) $person->setSpeedAccess($params['speedAccess']); - if(array_key_exists('address',$params)) + if (array_key_exists('address', $params)) $person->setAddress($params['address']); - if(array_key_exists('des',$params)) + if (array_key_exists('des', $params)) $person->setDes($params['des']); - if(array_key_exists('mobile',$params)) + if (array_key_exists('mobile', $params)) $person->setMobile($params['mobile']); - if(array_key_exists('mobile2',$params)) + if (array_key_exists('mobile2', $params)) $person->setMobile2($params['mobile2']); - if(array_key_exists('fax',$params)) + if (array_key_exists('fax', $params)) $person->setFax($params['fax']); - if(array_key_exists('website',$params)) + if (array_key_exists('website', $params)) $person->setWebsite($params['website']); - if(array_key_exists('email',$params)) + if (array_key_exists('email', $params)) $person->setEmail($params['email']); - if(array_key_exists('postalcode',$params)) + if (array_key_exists('postalcode', $params)) $person->setPostalcode($params['postalcode']); - if(array_key_exists('shahr',$params)) + if (array_key_exists('shahr', $params)) $person->setShahr($params['shahr']); - if(array_key_exists('ostan',$params)) + if (array_key_exists('ostan', $params)) $person->setOstan($params['ostan']); - if(array_key_exists('keshvar',$params)) + if (array_key_exists('keshvar', $params)) $person->setKeshvar($params['keshvar']); - if(array_key_exists('sabt',$params)) + if (array_key_exists('sabt', $params)) $person->setSabt($params['sabt']); - if(array_key_exists('codeeghtesadi',$params)) + if (array_key_exists('codeeghtesadi', $params)) $person->setCodeeghtesadi($params['codeeghtesadi']); - if(array_key_exists('shenasemeli',$params)) + if (array_key_exists('shenasemeli', $params)) $person->setShenasemeli($params['shenasemeli']); - if(array_key_exists('company',$params)) + if (array_key_exists('company', $params)) $person->setCompany($params['company']); //inset cards - if(array_key_exists('accounts',$params)){ - foreach($params['accounts'] as $item){ + if (array_key_exists('accounts', $params)) { + foreach ($params['accounts'] as $item) { $card = $entityManager->getRepository(PersonCard::class)->findOneBy([ - 'bid'=>$acc['bid'], - 'person'=>$person, - 'bank'=>$item['bank'] + 'bid' => $acc['bid'], + 'person' => $person, + 'bank' => $item['bank'] ]); - if(!$card) - $card = new PersonCard(); - + if (!$card) + $card = new PersonCard(); + $card->setPerson($person); $card->setBid($acc['bid']); $card->setShabaNum($item['shabaNum']); @@ -175,17 +175,17 @@ class PersonsController extends AbstractController } //remove not sended accounts $accounts = $entityManager->getRepository(PersonCard::class)->findBy([ - 'bid'=>$acc['bid'], - 'person'=>$person, + 'bid' => $acc['bid'], + 'person' => $person, ]); - foreach($accounts as $item){ + foreach ($accounts as $item) { $deleted = true; - foreach($params['accounts'] as $param){ - if($item->getBank() == $param['bank']){ + foreach ($params['accounts'] as $param) { + if ($item->getBank() == $param['bank']) { $deleted = false; } } - if($deleted){ + if ($deleted) { $entityManager->remove($item); } } @@ -193,81 +193,132 @@ class PersonsController extends AbstractController //insert new types $types = $entityManager->getRepository(PersonType::class)->findAll(); - foreach($params['types'] as $item){ - if($item['checked'] == true) + foreach ($params['types'] as $item) { + if ($item['checked'] == true) $person->addType($entityManager->getRepository(PersonType::class)->findOneBy([ - 'code'=>$item['code'] + 'code' => $item['code'] ])); - elseif($item['checked'] == false){ + elseif ($item['checked'] == false) { $person->removeType($entityManager->getRepository(PersonType::class)->findOneBy([ - 'code'=>$item['code'] + 'code' => $item['code'] ])); } } $entityManager->flush(); - $log->insert('اشخاص','شخص با نام مستعار ' . $params['nikename'] . ' افزوده/ویرایش شد.',$this->getUser(),$request->headers->get('activeBid')); + $log->insert('اشخاص', 'شخص با نام مستعار ' . $params['nikename'] . ' افزوده/ویرایش شد.', $this->getUser(), $request->headers->get('activeBid')); return $this->json(['result' => 1]); } - #[Route('/api/person/list/limit', name: 'app_persons_list_limit')] - public function app_persons_list_limit(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse + #[Route('/api/person/list/search', name: 'app_persons_list_search')] + public function app_persons_list_search(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { - if(!$access->hasRole('person')) + $acc = $access->hasRole('person'); + if (!$acc) throw $this->createAccessDeniedException(); $params = []; if ($content = $request->getContent()) { $params = json_decode($content, true); } - if(array_key_exists('speedAccess',$params)){ - $persons = $entityManager->getRepository(Person::class)->findBy([ - 'bid'=>$request->headers->get('activeBid'), - 'speedAccess'=>true + if (array_key_exists('search', $params)) + $persons = $entityManager->getRepository(Person::class)->searchByNikename($acc['bid'], $params['search'], 10); + else + $persons = $entityManager->getRepository(Person::class)->getLasts($acc['bid'], 10); + $response = []; + foreach ($persons as $key => $person) { + $temp = [ + 'id' => $person->getId(), + 'nikename' => $person->getNikename(), + 'code' => $person->getCode(), + 'mobile' => $person->getMobile() + ]; + $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ + 'person' => $person ]); + $bs = 0; + $bd = 0; + foreach ($rows as $row) { + $bs += $row->getBs(); + $bd += $row->getBd(); + } + $temp['bs'] = $bs; + $temp['bd'] = $bd; + $temp['balance'] = $bs - $bd; + $response[] = $temp; } - else{ + return $this->json($response); + } + + #[Route('/api/person/list/limit', name: 'app_persons_list_limit')] + public function app_persons_list_limit(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + if (!$access->hasRole('person')) + throw $this->createAccessDeniedException(); + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + if (array_key_exists('speedAccess', $params)) { $persons = $entityManager->getRepository(Person::class)->findBy([ - 'bid'=>$request->headers->get('activeBid') + 'bid' => $request->headers->get('activeBid'), + 'speedAccess' => true + ]); + } else { + $persons = $entityManager->getRepository(Person::class)->findBy([ + 'bid' => $request->headers->get('activeBid') ]); } $response = []; - foreach ($persons as $key =>$person){ - $response[] = [ + foreach ($persons as $key => $person) { + $temp = [ 'id' => $person->getId(), - 'nikename'=>$person->getNikename(), - 'code' =>$person->getCode(), + 'nikename' => $person->getNikename(), + 'code' => $person->getCode(), + 'mobile' => $person->getMobile() ]; + $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ + 'person' => $person + ]); + $bs = 0; + $bd = 0; + foreach ($rows as $row) { + $bs += $row->getBs(); + $bd += $row->getBd(); + } + $temp['bs'] = $bs; + $temp['bd'] = $bd; + $temp['balance'] = $bs - $bd; + $response[] = $temp; } return $this->json($response); } #[Route('/api/person/list', name: 'app_persons_list')] - public function app_persons_list(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): Response + public function app_persons_list(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): Response { - if(!$access->hasRole('person')) + if (!$access->hasRole('person')) throw $this->createAccessDeniedException(); $params = []; if ($content = $request->getContent()) { $params = json_decode($content, true); } - if(array_key_exists('speedAccess',$params)){ + if (array_key_exists('speedAccess', $params)) { $persons = $entityManager->getRepository(Person::class)->findBy([ - 'bid'=>$request->headers->get('activeBid'), - 'speedAccess'=>true + 'bid' => $request->headers->get('activeBid'), + 'speedAccess' => true + ]); + } else { + $persons = $entityManager->getRepository(Person::class)->findBy([ + 'bid' => $request->headers->get('activeBid') ]); } - else{ - $persons = $entityManager->getRepository(Person::class)->findBy([ - 'bid'=>$request->headers->get('activeBid') - ]); - } - $response = Explore::ExplorePersons($persons,$entityManager->getRepository(PersonType::class)->findAll()); - foreach ($persons as $key =>$person){ + $response = Explore::ExplorePersons($persons, $entityManager->getRepository(PersonType::class)->findAll()); + foreach ($persons as $key => $person) { $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ - 'person'=>$person + 'person' => $person ]); $bs = 0; $bd = 0; - foreach ($rows as $row){ + foreach ($rows as $row) { $bs += $row->getBs(); $bd += $row->getBd(); } @@ -279,34 +330,33 @@ class PersonsController extends AbstractController } #[Route('/api/person/list/debtors/{amount}', name: 'app_persons_list_debtors')] - public function app_persons_list_debtors(string $amount,Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse + public function app_persons_list_debtors(string $amount, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { - if(!$access->hasRole('person')) + if (!$access->hasRole('person')) throw $this->createAccessDeniedException(); $params = []; if ($content = $request->getContent()) { $params = json_decode($content, true); } - if(array_key_exists('speedAccess',$params)){ + if (array_key_exists('speedAccess', $params)) { $persons = $entityManager->getRepository(Person::class)->findBy([ - 'bid'=>$request->headers->get('activeBid'), - 'speedAccess'=>true + 'bid' => $request->headers->get('activeBid'), + 'speedAccess' => true ]); - } - else{ + } else { $persons = $entityManager->getRepository(Person::class)->findBy([ - 'bid'=>$request->headers->get('activeBid') + 'bid' => $request->headers->get('activeBid') ]); } - $response = $provider->ArrayEntity2Array($persons,0); - foreach ($persons as $key =>$person){ + $response = $provider->ArrayEntity2Array($persons, 0); + foreach ($persons as $key => $person) { $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ - 'person'=>$person + 'person' => $person ]); $bs = 0; $bd = 0; - foreach ($rows as $row){ + foreach ($rows as $row) { $bs += $row->getBs(); $bd += $row->getBd(); } @@ -315,31 +365,31 @@ class PersonsController extends AbstractController $response[$key]['balance'] = $bs - $bd; } $result = []; - foreach ($response as $key =>$person){ - if($person['bd'] - $person['bs'] > $amount ){ - array_push($result,$person); - } + foreach ($response as $key => $person) { + if ($person['bd'] - $person['bs'] > $amount) { + array_push($result, $person); + } } return $this->json($result); } #[Route('/api/person/list/debtors/print/{amount}', name: 'app_persons_debtors_list_print')] - public function app_persons_debtors_list_print(string $amount,Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse + public function app_persons_debtors_list_print(string $amount, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { $acc = $access->hasRole('person'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $persons = $entityManager->getRepository(Person::class)->findBy([ - 'bid'=>$request->headers->get('activeBid') + 'bid' => $request->headers->get('activeBid') ]); - $response = $provider->ArrayEntity2Array($persons,0); - foreach ($persons as $key =>$person){ + $response = $provider->ArrayEntity2Array($persons, 0); + foreach ($persons as $key => $person) { $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ - 'person'=>$person + 'person' => $person ]); $bs = 0; $bd = 0; - foreach ($rows as $row){ + foreach ($rows as $row) { $bs += $row->getBs(); $bd += $row->getBd(); } @@ -348,51 +398,51 @@ class PersonsController extends AbstractController $response[$key]['balance'] = $bs - $bd; } $result = []; - foreach ($response as $key =>$person){ - if($person['bd'] - $person['bs'] > $amount ){ - array_push($result,$person); - } + foreach ($response as $key => $person) { + if ($person['bd'] - $person['bs'] > $amount) { + array_push($result, $person); + } } $pid = $provider->createPrint( $acc['bid'], $this->getUser(), - $this->renderView('pdf/personsDebtors.html.twig',[ - 'page_title'=>'فهرست بدهکاران', - 'bid'=>$acc['bid'], - 'persons'=>$result - ])); - return $this->json(['id'=>$pid]); + $this->renderView('pdf/personsDebtors.html.twig', [ + 'page_title' => 'فهرست بدهکاران', + 'bid' => $acc['bid'], + 'persons' => $result + ]) + ); + return $this->json(['id' => $pid]); } #[Route('/api/person/list/depositors/{amount}', name: 'app_persons_list_depoistors')] - public function app_persons_list_depoistors(string $amount,Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse + public function app_persons_list_depoistors(string $amount, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { - if(!$access->hasRole('person')) + if (!$access->hasRole('person')) throw $this->createAccessDeniedException(); $params = []; if ($content = $request->getContent()) { $params = json_decode($content, true); } - if(array_key_exists('speedAccess',$params)){ + if (array_key_exists('speedAccess', $params)) { $persons = $entityManager->getRepository(Person::class)->findBy([ - 'bid'=>$request->headers->get('activeBid'), - 'speedAccess'=>true + 'bid' => $request->headers->get('activeBid'), + 'speedAccess' => true ]); - } - else{ + } else { $persons = $entityManager->getRepository(Person::class)->findBy([ - 'bid'=>$request->headers->get('activeBid') + 'bid' => $request->headers->get('activeBid') ]); } - $response = $provider->ArrayEntity2Array($persons,0); - foreach ($persons as $key =>$person){ + $response = $provider->ArrayEntity2Array($persons, 0); + foreach ($persons as $key => $person) { $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ - 'person'=>$person + 'person' => $person ]); $bs = 0; $bd = 0; - foreach ($rows as $row){ + foreach ($rows as $row) { $bs += $row->getBs(); $bd += $row->getBd(); } @@ -401,32 +451,32 @@ class PersonsController extends AbstractController $response[$key]['balance'] = $bs - $bd; } $result = []; - foreach ($response as $key =>$person){ - if($person['bs'] - $person['bd'] > $amount ){ - array_push($result,$person); - } + foreach ($response as $key => $person) { + if ($person['bs'] - $person['bd'] > $amount) { + array_push($result, $person); + } } return $this->json($result); } #[Route('/api/person/list/depositors/print/{amount}', name: 'app_persons_depositors_list_print')] - public function app_persons_depositors_list_print(string $amount,Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse + public function app_persons_depositors_list_print(string $amount, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { $acc = $access->hasRole('person'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $persons = $entityManager->getRepository(Person::class)->findBy([ - 'bid'=>$request->headers->get('activeBid') + 'bid' => $request->headers->get('activeBid') ]); - $response = $provider->ArrayEntity2Array($persons,0); - foreach ($persons as $key =>$person){ + $response = $provider->ArrayEntity2Array($persons, 0); + foreach ($persons as $key => $person) { $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ - 'person'=>$person + 'person' => $person ]); $bs = 0; $bd = 0; - foreach ($rows as $row){ + foreach ($rows as $row) { $bs += $row->getBs(); $bd += $row->getBd(); } @@ -435,85 +485,85 @@ class PersonsController extends AbstractController $response[$key]['balance'] = $bs - $bd; } $result = []; - foreach ($response as $key =>$person){ - if($person['bs'] - $person['bd'] > $amount ){ - array_push($result,$person); - } + foreach ($response as $key => $person) { + if ($person['bs'] - $person['bd'] > $amount) { + array_push($result, $person); + } } $pid = $provider->createPrint( $acc['bid'], $this->getUser(), - $this->renderView('pdf/personsDepositors.html.twig',[ - 'page_title'=>'فهرست بستانکاران', - 'bid'=>$acc['bid'], - 'persons'=>$result - ])); - return $this->json(['id'=>$pid]); + $this->renderView('pdf/personsDepositors.html.twig', [ + 'page_title' => 'فهرست بستانکاران', + 'bid' => $acc['bid'], + 'persons' => $result + ]) + ); + return $this->json(['id' => $pid]); } #[Route('/api/person/list/print', name: 'app_persons_list_print')] - public function app_persons_list_print(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse + public function app_persons_list_print(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { $acc = $access->hasRole('person'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $params = []; if ($content = $request->getContent()) { $params = json_decode($content, true); } - if(!array_key_exists('items',$params)){ + if (!array_key_exists('items', $params)) { $persons = $entityManager->getRepository(Person::class)->findBy([ - 'bid'=>$acc['bid'] + 'bid' => $acc['bid'] ]); - } - else{ + } else { $persons = []; - foreach ($params['items'] as $param){ + foreach ($params['items'] as $param) { $prs = $entityManager->getRepository(Person::class)->findOneBy([ - 'id'=>$param['id'], - 'bid'=>$acc['bid'] + 'id' => $param['id'], + 'bid' => $acc['bid'] ]); - if($prs) + if ($prs) $persons[] = $prs; } } $pid = $provider->createPrint( $acc['bid'], $this->getUser(), - $this->renderView('pdf/persons.html.twig',[ - 'page_title'=>'فهرست اشخاص', - 'bid'=>$acc['bid'], - 'persons'=>$persons - ])); - return $this->json(['id'=>$pid]); + $this->renderView('pdf/persons.html.twig', [ + 'page_title' => 'فهرست اشخاص', + 'bid' => $acc['bid'], + 'persons' => $persons + ]) + ); + return $this->json(['id' => $pid]); } /** * @throws Exception */ #[Route('/api/person/list/excel', name: 'app_persons_list_excel')] - public function app_persons_list_excel(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): BinaryFileResponse | JsonResponse | StreamedResponse + public function app_persons_list_excel(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): BinaryFileResponse | JsonResponse | StreamedResponse { $acc = $access->hasRole('person'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $params = []; if ($content = $request->getContent()) { $params = json_decode($content, true); } - if(!array_key_exists('items',$params)){ + if (!array_key_exists('items', $params)) { $persons = $entityManager->getRepository(Person::class)->findBy([ - 'bid'=>$acc['bid'] + 'bid' => $acc['bid'] ]); - } - else{ + } else { $persons = []; - foreach ($params['items'] as $param){ + foreach ($params['items'] as $param) { $prs = $entityManager->getRepository(Person::class)->findOneBy([ - 'id'=>$param['id'], - 'bid'=>$acc['bid'] + 'id' => $param['id'], + 'bid' => $acc['bid'] ]); - if($prs) + if ($prs) $persons[] = $prs; } } @@ -524,37 +574,36 @@ class PersonsController extends AbstractController * @throws Exception */ #[Route('/api/person/card/list/excel', name: 'app_persons_card_list_excel')] - public function app_persons_card_list_excel(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): BinaryFileResponse | JsonResponse | StreamedResponse + public function app_persons_card_list_excel(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): BinaryFileResponse | JsonResponse | StreamedResponse { $acc = $access->hasRole('person'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $params = []; if ($content = $request->getContent()) { $params = json_decode($content, true); } - if(!array_key_exists('code',$params)) + if (!array_key_exists('code', $params)) throw $this->createNotFoundException(); - $person = $entityManager->getRepository(Person::class)->findOneBy(['bid'=>$acc['bid'],'code'=>$params['code']]); - if(!$person) + $person = $entityManager->getRepository(Person::class)->findOneBy(['bid' => $acc['bid'], 'code' => $params['code']]); + if (!$person) throw $this->createNotFoundException(); - if(!array_key_exists('items',$params)){ + if (!array_key_exists('items', $params)) { $transactions = $entityManager->getRepository(HesabdariRow::class)->findBy([ - 'bid'=>$acc['bid'], - 'person'=>$person + 'bid' => $acc['bid'], + 'person' => $person ]); - } - else{ + } else { $transactions = []; - foreach ($params['items'] as $param){ + foreach ($params['items'] as $param) { $prs = $entityManager->getRepository(HesabdariRow::class)->findOneBy([ - 'id'=>$param['id'], - 'bid'=>$acc['bid'], - 'person'=>$person + 'id' => $param['id'], + 'bid' => $acc['bid'], + 'person' => $person ]); - if($prs){ + if ($prs) { $transactions[] = $prs; - } + } } } $spreadsheet = new Spreadsheet(); @@ -568,8 +617,8 @@ class PersonsController extends AbstractController 'بدهکار', 'سال مالی', ]]; - foreach($transactions as $transaction){ - $arrayEntity[] =[ + foreach ($transactions as $transaction) { + $arrayEntity[] = [ $transaction->getId(), $transaction->getDoc()->getDate(), $transaction->getDes(), @@ -579,219 +628,217 @@ class PersonsController extends AbstractController $transaction->getYear()->getlabel() ]; } - $activeWorksheet->fromArray($arrayEntity,null,'A1'); + $activeWorksheet->fromArray($arrayEntity, null, 'A1'); $activeWorksheet->setRightToLeft(true); $writer = new Xlsx($spreadsheet); - $filePath = __DIR__ . '/../../var/'.$this->RandomString(12).'.xlsx'; - $writer->save($filePath); + $filePath = __DIR__ . '/../../var/' . $this->RandomString(12) . '.xlsx'; + $writer->save($filePath); return new BinaryFileResponse($filePath); } #[Route('/api/person/card/list/print', name: 'app_persons_card_list_print')] - public function app_persons_card_list_print(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse + public function app_persons_card_list_print(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { $acc = $access->hasRole('person_receive'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $params = []; if ($content = $request->getContent()) { $params = json_decode($content, true); } - if(!array_key_exists('code',$params)) + if (!array_key_exists('code', $params)) throw $this->createNotFoundException(); - $person = $entityManager->getRepository(Person::class)->findOneBy(['bid'=>$acc['bid'],'code'=>$params['code']]); - if(!$person) + $person = $entityManager->getRepository(Person::class)->findOneBy(['bid' => $acc['bid'], 'code' => $params['code']]); + if (!$person) throw $this->createNotFoundException(); - if(!array_key_exists('items',$params)){ + if (!array_key_exists('items', $params)) { $transactions = $entityManager->getRepository(HesabdariRow::class)->findBy([ - 'bid'=>$acc['bid'], - 'person'=>$person + 'bid' => $acc['bid'], + 'person' => $person ]); - } - else{ + } else { $transactions = []; - foreach ($params['items'] as $param){ + foreach ($params['items'] as $param) { $prs = $entityManager->getRepository(HesabdariRow::class)->findOneBy([ - 'id'=>$param['id'], - 'bid'=>$acc['bid'], - 'person'=>$person + 'id' => $param['id'], + 'bid' => $acc['bid'], + 'person' => $person ]); - if($prs){ + if ($prs) { $transactions[] = $prs; - } + } } } $pid = $provider->createPrint( $acc['bid'], $this->getUser(), - $this->renderView('pdf/person_card.html.twig',[ - 'page_title'=>'کارت حساب' . ' ' . $person->getNikename(), - 'bid'=>$acc['bid'], - 'items'=>$transactions - ])); - return $this->json(['id'=>$pid]); + $this->renderView('pdf/person_card.html.twig', [ + 'page_title' => 'کارت حساب' . ' ' . $person->getNikename(), + 'bid' => $acc['bid'], + 'items' => $transactions + ]) + ); + return $this->json(['id' => $pid]); } #[Route('/api/person/receive/list/print', name: 'app_persons_receive_list_print')] - public function app_persons_receive_list_print(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse + public function app_persons_receive_list_print(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { $acc = $access->hasRole('person_receive'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $params = []; if ($content = $request->getContent()) { $params = json_decode($content, true); } - if(!array_key_exists('items',$params)){ + if (!array_key_exists('items', $params)) { $items = $entityManager->getRepository(HesabdariDoc::class)->findBy([ - 'bid'=>$acc['bid'], - 'type'=>'person_receive', - 'year'=>$acc['year'] + 'bid' => $acc['bid'], + 'type' => 'person_receive', + 'year' => $acc['year'] ]); - } - else{ + } else { $items = []; - foreach ($params['items'] as $param){ + foreach ($params['items'] as $param) { $prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ - 'id'=>$param['id'], - 'bid'=>$acc['bid'], - 'type'=>'person_receive', - 'year'=>$acc['year'] + 'id' => $param['id'], + 'bid' => $acc['bid'], + 'type' => 'person_receive', + 'year' => $acc['year'] ]); - if($prs) + if ($prs) $items[] = $prs; } } $pid = $provider->createPrint( $acc['bid'], $this->getUser(), - $this->renderView('pdf/persons_receive.html.twig',[ - 'page_title'=>'لیست دریافت‌ها', - 'bid'=>$acc['bid'], - 'items'=>$items - ])); - return $this->json(['id'=>$pid]); + $this->renderView('pdf/persons_receive.html.twig', [ + 'page_title' => 'لیست دریافت‌ها', + 'bid' => $acc['bid'], + 'items' => $items + ]) + ); + return $this->json(['id' => $pid]); } /** * @throws Exception */ #[Route('/api/person/receive/list/excel', name: 'app_persons_receive_list_excel')] - public function app_persons_receive_list_excel(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): BinaryFileResponse | JsonResponse | StreamedResponse + public function app_persons_receive_list_excel(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): BinaryFileResponse | JsonResponse | StreamedResponse { $acc = $access->hasRole('person_receive'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $params = []; if ($content = $request->getContent()) { $params = json_decode($content, true); } - if(!array_key_exists('items',$params)){ + if (!array_key_exists('items', $params)) { $items = $entityManager->getRepository(HesabdariDoc::class)->findBy([ - 'bid'=>$acc['bid'], - 'type'=>'person_receive', - 'year'=>$acc['year'] + 'bid' => $acc['bid'], + 'type' => 'person_receive', + 'year' => $acc['year'] ]); - } - else{ + } else { $items = []; - foreach ($params['items'] as $param){ + foreach ($params['items'] as $param) { $prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ - 'id'=>$param['id'], - 'bid'=>$acc['bid'], - 'type'=>'person_receive', - 'year'=>$acc['year'] + 'id' => $param['id'], + 'bid' => $acc['bid'], + 'type' => 'person_receive', + 'year' => $acc['year'] ]); - if($prs) + if ($prs) $items[] = $prs; } } - return new BinaryFileResponse($provider->createExcell($items,['type','dateSubmit'])); + return new BinaryFileResponse($provider->createExcell($items, ['type', 'dateSubmit'])); } #[Route('/api/person/send/list/print', name: 'app_persons_send_list_print')] - public function app_persons_send_list_print(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse + public function app_persons_send_list_print(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { $acc = $access->hasRole('person_send'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $params = []; if ($content = $request->getContent()) { $params = json_decode($content, true); } - if(!array_key_exists('items',$params)){ + if (!array_key_exists('items', $params)) { $items = $entityManager->getRepository(HesabdariDoc::class)->findBy([ - 'bid'=>$acc['bid'], - 'type'=>'person_send', - 'year'=>$acc['year'] + 'bid' => $acc['bid'], + 'type' => 'person_send', + 'year' => $acc['year'] ]); - } - else{ + } else { $items = []; - foreach ($params['items'] as $param){ + foreach ($params['items'] as $param) { $prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ - 'id'=>$param['id'], - 'bid'=>$acc['bid'], - 'type'=>'person_send', - 'year'=>$acc['year'] + 'id' => $param['id'], + 'bid' => $acc['bid'], + 'type' => 'person_send', + 'year' => $acc['year'] ]); - if($prs) + if ($prs) $items[] = $prs; } } $pid = $provider->createPrint( $acc['bid'], $this->getUser(), - $this->renderView('pdf/persons_receive.html.twig',[ - 'page_title'=>'لیست پرداخت‌ها', - 'bid'=>$acc['bid'], - 'items'=>$items - ])); - return $this->json(['id'=>$pid]); + $this->renderView('pdf/persons_receive.html.twig', [ + 'page_title' => 'لیست پرداخت‌ها', + 'bid' => $acc['bid'], + 'items' => $items + ]) + ); + return $this->json(['id' => $pid]); } /** * @throws Exception */ #[Route('/api/person/send/list/excel', name: 'app_persons_send_list_excel')] - public function app_persons_send_list_excel(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): BinaryFileResponse | JsonResponse | StreamedResponse + public function app_persons_send_list_excel(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): BinaryFileResponse | JsonResponse | StreamedResponse { $acc = $access->hasRole('person_send'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $params = []; if ($content = $request->getContent()) { $params = json_decode($content, true); } - if(!array_key_exists('items',$params)){ + if (!array_key_exists('items', $params)) { $items = $entityManager->getRepository(HesabdariDoc::class)->findBy([ - 'bid'=>$acc['bid'], - 'type'=>'person_send', - 'year'=>$acc['year'] + 'bid' => $acc['bid'], + 'type' => 'person_send', + 'year' => $acc['year'] ]); - } - else{ + } else { $items = []; - foreach ($params['items'] as $param){ + foreach ($params['items'] as $param) { $prs = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ - 'id'=>$param['id'], - 'bid'=>$acc['bid'], - 'type'=>'person_send', - 'year'=>$acc['year'] + 'id' => $param['id'], + 'bid' => $acc['bid'], + 'type' => 'person_send', + 'year' => $acc['year'] ]); - if($prs) + if ($prs) $items[] = $prs; } } - return new BinaryFileResponse($provider->createExcell($items,['type','dateSubmit'])); + return new BinaryFileResponse($provider->createExcell($items, ['type', 'dateSubmit'])); } #[Route('/api/person/import/excel', name: 'app_persons_import_excel')] - public function app_persons_import_excel(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse + public function app_persons_import_excel(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse { $acc = $access->hasRole('person'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); $file = $request->files->get('file'); $reader = new \PhpOffice\PhpSpreadsheet\Reader\Xlsx(); @@ -800,60 +847,59 @@ class PersonsController extends AbstractController $sheet = $spreadsheet->getSheet($spreadsheet->getFirstSheetIndex()); $data = $sheet->toArray(); unset($data[0]); - foreach($data as $item){ + foreach ($data as $item) { $person = $entityManager->getRepository(Person::class)->findOneBy([ - 'nikename'=>$item[0], - 'bid' =>$acc['bid'] + 'nikename' => $item[0], + 'bid' => $acc['bid'] ]); //check exist before - if(!$person){ + if (!$person) { $person = new Person(); - $person->setCode($provider->getAccountingCode($request->headers->get('activeBid'),'person')); + $person->setCode($provider->getAccountingCode($request->headers->get('activeBid'), 'person')); $person->setNikename($item[0]); $person->setBid($acc['bid']); - - if(array_key_exists(1,$item)) + + if (array_key_exists(1, $item)) $person->setName($item[1]); - if(array_key_exists(4,$item)) + if (array_key_exists(4, $item)) $person->setBirthday($item[4]); - if(array_key_exists(10,$item)) + if (array_key_exists(10, $item)) $person->setTel($item[10]); - if(array_key_exists(2,$item)) + if (array_key_exists(2, $item)) $person->setSpeedAccess($item[2]); - if(array_key_exists(18,$item)) + if (array_key_exists(18, $item)) $person->setAddress($item[18]); - if(array_key_exists(5,$item)) + if (array_key_exists(5, $item)) $person->setDes($item[5]); - if(array_key_exists(9,$item)) + if (array_key_exists(9, $item)) $person->setMobile($item[9]); - if(array_key_exists(11,$item)) + if (array_key_exists(11, $item)) $person->setFax($item[11]); - if(array_key_exists(13,$item)) + if (array_key_exists(13, $item)) $person->setWebsite($item[13]); - if(array_key_exists(12,$item)) + if (array_key_exists(12, $item)) $person->setEmail($item[12]); - if(array_key_exists(17,$item)) + if (array_key_exists(17, $item)) $person->setPostalcode($item[17]); - if(array_key_exists(16,$item)) + if (array_key_exists(16, $item)) $person->setShahr($item[16]); - if(array_key_exists(15,$item)) + if (array_key_exists(15, $item)) $person->setOstan($item[15]); - if(array_key_exists(14,$item)) + if (array_key_exists(14, $item)) $person->setKeshvar($item[14]); - if(array_key_exists(7,$item)) + if (array_key_exists(7, $item)) $person->setSabt($item[7]); - if(array_key_exists(8,$item)) + if (array_key_exists(8, $item)) $person->setCodeeghtesadi($item[8]); - if(array_key_exists(6,$item)) + if (array_key_exists(6, $item)) $person->setShenasemeli($item[6]); - if(array_key_exists(3,$item)) + if (array_key_exists(3, $item)) $person->setCompany($item[3]); $entityManager->persist($person); } - $entityManager->flush(); + $entityManager->flush(); } - $log->insert('اشخاص','تعداد '. count($data) . ' شخص به صورت گروهی وارد شد.',$this->getUser(),$request->headers->get('activeBid')); + $log->insert('اشخاص', 'تعداد ' . count($data) . ' شخص به صورت گروهی وارد شد.', $this->getUser(), $request->headers->get('activeBid')); return $this->json(['result' => 1]); } - } diff --git a/hesabixCore/src/Repository/PersonRepository.php b/hesabixCore/src/Repository/PersonRepository.php index 6cfaff5..89cc91a 100644 --- a/hesabixCore/src/Repository/PersonRepository.php +++ b/hesabixCore/src/Repository/PersonRepository.php @@ -3,8 +3,9 @@ namespace App\Repository; use App\Entity\Person; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use App\Entity\Business; use Doctrine\Persistence\ManagerRegistry; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; /** * @extends ServiceEntityRepository @@ -39,6 +40,36 @@ class PersonRepository extends ServiceEntityRepository } } + /** + * @return Person[] Returns an array of Person objects + */ + public function searchByNikename(Business $bid,string $search,int $maxResults = 10): array + { + return $this->createQueryBuilder('p') + ->andWhere('p.bid = :val') + ->andWhere("p.nikename LIKE :search") + ->setParameter('val', $bid) + ->setParameter('search', '%' . $search . '%') + ->setMaxResults($maxResults) + ->orderBy('p.id', 'ASC') + ->getQuery() + ->getResult(); + } + + /** + * @return Person[] Returns an array of Person objects + */ + public function getLasts(Business $bid,int $maxResults = 10): array + { + return $this->createQueryBuilder('p') + ->andWhere('p.bid = :val') + ->setParameter('val', $bid) + ->setMaxResults($maxResults) + ->orderBy('p.id', 'ASC') + ->getQuery() + ->getResult(); + } + /** * @return Person[] Returns an array of Person objects */ @@ -53,17 +84,16 @@ class PersonRepository extends ServiceEntityRepository ->setParameter('val', $bid) ->orderBy('p.id', 'ASC') ->getQuery() - ->getResult() - ; + ->getResult(); } -// public function findOneBySomeField($value): ?Person -// { -// return $this->createQueryBuilder('p') -// ->andWhere('p.exampleField = :val') -// ->setParameter('val', $value) -// ->getQuery() -// ->getOneOrNullResult() -// ; -// } + // public function findOneBySomeField($value): ?Person + // { + // return $this->createQueryBuilder('p') + // ->andWhere('p.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } }