progress in import persons by hook

This commit is contained in:
Hesabix 2024-01-14 00:32:12 +00:00
parent c03ad96afa
commit 899724ceef

View file

@ -279,6 +279,88 @@ class HookController extends AbstractController
$log->insert('کالا و خدمات','کالا / خدمات از طریق hook با نام ' . $item['name'] . ' افزوده/ویرایش شد.',$this->getUser(),$request->headers->get('activeBid')); $log->insert('کالا و خدمات','کالا / خدمات از طریق hook با نام ' . $item['name'] . ' افزوده/ویرایش شد.',$this->getUser(),$request->headers->get('activeBid'));
} }
return $this->json([
'Success'=>true,
'ErrorCode' => 0,
'ErrorMessage' => '',
'Result' =>'ok'
]);
}
#[Route('hooks/person/import ', name: 'api_hooks_person_import')]
public function api_hooks_person_import(Provider $provider,Access $access,Log $log,Request $request,EntityManagerInterface $entityManager): JsonResponse
{
$acc = $access->hasRole('person');
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){
$person = $entityManager->getRepository(Person::class)->findOneBy([
'nikename'=>$params['nikename'],
'bid' =>$acc['bid']
]);
//check exist before
if($person)
return $this->json(['result'=>2]);
$person = new Person();
$person->setCode($provider->getAccountingCode($request->headers->get('activeBid'),'person'));
}
else{
$person = $entityManager->getRepository(Person::class)->findOneBy([
'bid'=>$acc['bid'],
'code'=>$code
]);
if(!$person)
throw $this->createNotFoundException();
}
$person->setBid($acc['bid']);
$person->setNikename($params['nikename']);
if(array_key_exists('name',$params))
$person->setName($params['name']);
if(array_key_exists('birthday',$params))
$person->setBirthday($params['birthday']);
if(array_key_exists('tel',$params))
$person->setTel($params['tel']);
if(array_key_exists('speedAccess',$params))
$person->setSpeedAccess($params['speedAccess']);
if(array_key_exists('address',$params))
$person->setAddress($params['address']);
if(array_key_exists('des',$params))
$person->setDes($params['des']);
if(array_key_exists('mobile',$params))
$person->setMobile($params['mobile']);
if(array_key_exists('fax',$params))
$person->setFax($params['fax']);
if(array_key_exists('website',$params))
$person->setWebsite($params['website']);
if(array_key_exists('email',$params))
$person->setEmail($params['email']);
if(array_key_exists('postalcode',$params))
$person->setPostalcode($params['postalcode']);
if(array_key_exists('shahr',$params))
$person->setShahr($params['shahr']);
if(array_key_exists('ostan',$params))
$person->setOstan($params['ostan']);
if(array_key_exists('keshvar',$params))
$person->setKeshvar($params['keshvar']);
if(array_key_exists('sabt',$params))
$person->setSabt($params['sabt']);
if(array_key_exists('codeeghtesadi',$params))
$person->setCodeeghtesadi($params['codeeghtesadi']);
if(array_key_exists('shenasemeli',$params))
$person->setShenasemeli($params['shenasemeli']);
if(array_key_exists('company',$params))
$person->setCompany($params['company']);
$entityManager->persist($person);
$entityManager->flush();
$log->insert('اشخاص','شخص با نام مستعار ' . $params['nikename'] . ' افزوده/ویرایش شد.',$this->getUser(),$request->headers->get('activeBid'));
return $this->json(['result' => 1]); return $this->json(['result' => 1]);
return $this->json([ return $this->json([
'Success'=>true, 'Success'=>true,