some progress and bug fix

This commit is contained in:
Hesabix 2024-05-10 13:10:56 +00:00
parent d5b42b598f
commit 694a06b090
8 changed files with 388 additions and 342 deletions

0
hesabixArchive/index.php Normal file → Executable file
View file

0
hesabixArchive/temp/index.php Normal file → Executable file
View file

View file

@ -255,6 +255,7 @@ class ArchiveController extends AbstractController
$newFilename $newFilename
);} catch (FileException $e) { );} catch (FileException $e) {
// ... handle exception if something happens during file upload // ... handle exception if something happens during file upload
return $this->json("error");
} }
// updates the 'brochureFilename' property to store the PDF file name // updates the 'brochureFilename' property to store the PDF file name

View file

@ -16,72 +16,71 @@ use Symfony\Component\Routing\Annotation\Route;
class BankController extends AbstractController class BankController extends AbstractController
{ {
#[Route('/api/bank/list', name: 'app_bank_list')] #[Route('/api/bank/list', name: 'app_bank_list')]
public function app_bank_list(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse public function app_bank_list(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{ {
if(!$access->hasRole('banks')) if (!$access->hasRole('banks'))
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$datas = $entityManager->getRepository(BankAccount::class)->findBy([ $datas = $entityManager->getRepository(BankAccount::class)->findBy([
'bid'=>$request->headers->get('activeBid') 'bid' => $request->headers->get('activeBid')
]); ]);
foreach($datas as $data){ foreach ($datas as $data) {
$bs = 0; $bs = 0;
$bd = 0; $bd = 0;
$items = $entityManager->getRepository(HesabdariRow::class)->findBy([ $items = $entityManager->getRepository(HesabdariRow::class)->findBy([
'bank'=>$data 'bank' => $data
]); ]);
foreach ($items as $item){ foreach ($items as $item) {
$bs += $item->getBs(); $bs += $item->getBs();
$bd += $item->getBd(); $bd += $item->getBd();
} }
$data->setBalance($bd - $bs); $data->setBalance($bd - $bs);
} }
return $this->json($provider->ArrayEntity2Array($datas,0)); return $this->json($provider->ArrayEntity2Array($datas, 0));
} }
#[Route('/api/bank/info/{code}', name: 'app_bank_info')] #[Route('/api/bank/info/{code}', name: 'app_bank_info')]
public function app_bank_info($code,Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse public function app_bank_info($code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{ {
$acc = $access->hasRole('banks'); $acc = $access->hasRole('banks');
if(!$acc) if (!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$data = $entityManager->getRepository(BankAccount::class)->findOneBy([ $data = $entityManager->getRepository(BankAccount::class)->findOneBy([
'bid'=>$acc['bid'], 'bid' => $acc['bid'],
'code'=>$code 'code' => $code
]); ]);
return $this->json($provider->Entity2Array($data,0)); return $this->json($provider->Entity2Array($data, 0));
} }
#[Route('/api/bank/mod/{code}', name: 'app_bank_mod')] #[Route('/api/bank/mod/{code}', name: 'app_bank_mod')]
public function app_bank_mod(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse public function app_bank_mod(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse
{ {
$acc = $access->hasRole('banks'); $acc = $access->hasRole('banks');
if(!$acc) if (!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$params = []; $params = [];
if ($content = $request->getContent()) { if ($content = $request->getContent()) {
$params = json_decode($content, true); $params = json_decode($content, true);
} }
if(!array_key_exists('name',$params)) if (!array_key_exists('name', $params))
return $this->json(['result'=>-1]); return $this->json(['result' => -1]);
if(count_chars(trim($params['name'])) == 0) if (count_chars(trim($params['name'])) == 0)
return $this->json(['result'=>3]); return $this->json(['result' => 3]);
if($code == 0){ if ($code == 0) {
$data = $entityManager->getRepository(BankAccount::class)->findOneBy([ $data = $entityManager->getRepository(BankAccount::class)->findOneBy([
'name'=>$params['name'], 'name' => $params['name'],
'bid' =>$acc['bid'] 'bid' => $acc['bid']
]); ]);
//check exist before //check exist before
if($data) if ($data)
return $this->json(['result'=>2]); return $this->json(['result' => 2]);
$data = new BankAccount(); $data = new BankAccount();
$data->setCode($provider->getAccountingCode($request->headers->get('activeBid'),'bank')); $data->setCode($provider->getAccountingCode($request->headers->get('activeBid'), 'bank'));
} } else {
else{
$data = $entityManager->getRepository(BankAccount::class)->findOneBy([ $data = $entityManager->getRepository(BankAccount::class)->findOneBy([
'bid'=>$acc['bid'], 'bid' => $acc['bid'],
'code'=>$code 'code' => $code
]); ]);
if(!$data) if (!$data)
throw $this->createNotFoundException(); throw $this->createNotFoundException();
} }
$data->setBid($acc['bid']); $data->setBid($acc['bid']);
@ -96,7 +95,29 @@ class BankController extends AbstractController
$data->setMobileInternetBank($params['mobileInternetbank']); $data->setMobileInternetBank($params['mobileInternetbank']);
$entityManager->persist($data); $entityManager->persist($data);
$entityManager->flush(); $entityManager->flush();
$log->insert('بانک','حساب بانکی با نام ' . $params['name'] . ' افزوده/ویرایش شد.',$this->getUser(),$request->headers->get('activeBid')); $log->insert('بانک', 'حساب بانکی با نام ' . $params['name'] . ' افزوده/ویرایش شد.', $this->getUser(), $request->headers->get('activeBid'));
return $this->json(['result' => 1]);
}
#[Route('/api/bank/delete/{code}', name: 'app_bank_delete')]
public function app_bank_delete(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse
{
$acc = $access->hasRole('banks');
if (!$acc)
throw $this->createAccessDeniedException();
$bank = $entityManager->getRepository(BankAccount::class)->findOneBy(['bid' => $acc['bid'], 'code' => $code]);
if (!$bank)
throw $this->createNotFoundException();
//check accounting docs
$rows = $entityManager->getRepository(HesabdariRow::class)->findby(['bid' => $acc['bid'], 'bank' => $bank]);
if (count($rows) > 0)
return $this->json(['result' => 2]);
if ($acc['bid']->getWalletMatchBank()->getId() == $bank->getId())
return $this->json(['result' => 3]);
$name = $bank->getName();
$entityManager->remove($bank);
$log->insert('بانکداری', ' حساب بانکی با نام ' . $name . ' حذف شد. ', $this->getUser(), $acc['bid']->getId());
return $this->json(['result' => 1]); return $this->json(['result' => 1]);
} }
} }

View file

@ -17,20 +17,20 @@ use Symfony\Component\Routing\Annotation\Route;
class CashdeskController extends AbstractController class CashdeskController extends AbstractController
{ {
#[Route('/api/cashdesk/list', name: 'app_cashdesk_list')] #[Route('/api/cashdesk/list', name: 'app_cashdesk_list')]
public function app_cashdesk_list(Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse public function app_cashdesk_list(Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{ {
if(!$access->hasRole('cashdesk')) if (!$access->hasRole('cashdesk'))
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$datas = $entityManager->getRepository(Cashdesk::class)->findBy([ $datas = $entityManager->getRepository(Cashdesk::class)->findBy([
'bid'=>$request->headers->get('activeBid') 'bid' => $request->headers->get('activeBid')
]); ]);
foreach($datas as $data){ foreach ($datas as $data) {
$bs = 0; $bs = 0;
$bd = 0; $bd = 0;
$items = $entityManager->getRepository(HesabdariRow::class)->findBy([ $items = $entityManager->getRepository(HesabdariRow::class)->findBy([
'cashdesk'=>$data 'cashdesk' => $data
]); ]);
foreach ($items as $item){ foreach ($items as $item) {
$bs += $item->getBs(); $bs += $item->getBs();
$bd += $item->getBd(); $bd += $item->getBd();
} }
@ -40,49 +40,48 @@ class CashdeskController extends AbstractController
} }
#[Route('/api/cashdesk/info/{code}', name: 'app_cashdesk_info')] #[Route('/api/cashdesk/info/{code}', name: 'app_cashdesk_info')]
public function app_cashdesk_info($code,Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse public function app_cashdesk_info($code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{ {
$acc = $access->hasRole('cashdesk'); $acc = $access->hasRole('cashdesk');
if(!$acc) if (!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$data = $entityManager->getRepository(Cashdesk::class)->findOneBy([ $data = $entityManager->getRepository(Cashdesk::class)->findOneBy([
'bid'=>$acc['bid'], 'bid' => $acc['bid'],
'code'=>$code 'code' => $code
]); ]);
return $this->json($data); return $this->json($data);
} }
#[Route('/api/cashdesk/mod/{code}', name: 'app_cashdesk_mod')] #[Route('/api/cashdesk/mod/{code}', name: 'app_cashdesk_mod')]
public function app_cashdesk_mod(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse public function app_cashdesk_mod(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse
{ {
$acc = $access->hasRole('cashdesk'); $acc = $access->hasRole('cashdesk');
if(!$acc) if (!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$params = []; $params = [];
if ($content = $request->getContent()) { if ($content = $request->getContent()) {
$params = json_decode($content, true); $params = json_decode($content, true);
} }
if(!array_key_exists('name',$params)) if (!array_key_exists('name', $params))
return $this->json(['result'=>-1]); return $this->json(['result' => -1]);
if(count_chars(trim($params['name'])) == 0) if (count_chars(trim($params['name'])) == 0)
return $this->json(['result'=>3]); return $this->json(['result' => 3]);
if($code == 0){ if ($code == 0) {
$data = $entityManager->getRepository(Cashdesk::class)->findOneBy([ $data = $entityManager->getRepository(Cashdesk::class)->findOneBy([
'name'=>$params['name'], 'name' => $params['name'],
'bid' =>$acc['bid'] 'bid' => $acc['bid']
]); ]);
//check exist before //check exist before
if($data) if ($data)
return $this->json(['result'=>2]); return $this->json(['result' => 2]);
$data = new Cashdesk(); $data = new Cashdesk();
$data->setCode($provider->getAccountingCode($request->headers->get('activeBid'),'cashdesk')); $data->setCode($provider->getAccountingCode($request->headers->get('activeBid'), 'cashdesk'));
} } else {
else{
$data = $entityManager->getRepository(Cashdesk::class)->findOneBy([ $data = $entityManager->getRepository(Cashdesk::class)->findOneBy([
'bid'=>$acc['bid'], 'bid' => $acc['bid'],
'code'=>$code 'code' => $code
]); ]);
if(!$data) if (!$data)
throw $this->createNotFoundException(); throw $this->createNotFoundException();
} }
$data->setBid($acc['bid']); $data->setBid($acc['bid']);
@ -90,7 +89,28 @@ class CashdeskController extends AbstractController
$data->setDes($params['des']); $data->setDes($params['des']);
$entityManager->persist($data); $entityManager->persist($data);
$entityManager->flush(); $entityManager->flush();
$log->insert('بانک‌داری',' صندوق با نام ' . $params['name'] . ' افزوده/ویرایش شد.',$this->getUser(),$request->headers->get('activeBid')); $log->insert('بانک‌داری', ' صندوق با نام ' . $params['name'] . ' افزوده/ویرایش شد.', $this->getUser(), $request->headers->get('activeBid'));
return $this->json(['result' => 1]);
}
#[Route('/api/cashdesk/delete/{code}', name: 'app_cashdesk_delete')]
public function app_cashdesk_delete(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse
{
$acc = $access->hasRole('cashdesk');
if (!$acc)
throw $this->createAccessDeniedException();
$cashdesk = $entityManager->getRepository(Cashdesk::class)->findOneBy(['bid' => $acc['bid'], 'code' => $code]);
if (!$cashdesk)
throw $this->createNotFoundException();
//check accounting docs
$rows = $entityManager->getRepository(HesabdariRow::class)->findby(['bid' => $acc['bid'], 'cashdesk' => $cashdesk]);
if (count($rows) > 0)
return $this->json(['result' => 2]);
$name = $cashdesk->getName();
$entityManager->remove($cashdesk);
$log->insert('بانکداری', ' صندوق با نام ' . $name . ' حذف شد. ', $this->getUser(), $acc['bid']->getId());
return $this->json(['result' => 1]); return $this->json(['result' => 1]);
} }
} }

View file

@ -32,38 +32,39 @@ class HesabdariController extends AbstractController
{ {
private array $tableExport = []; private array $tableExport = [];
#[Route('/api/accounting/doc/get', name: 'app_accounting_doc_get')] #[Route('/api/accounting/doc/get', name: 'app_accounting_doc_get')]
public function app_accounting_doc_get(Jdate $jdate,Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse public function app_accounting_doc_get(Jdate $jdate, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{ {
$params = []; $params = [];
if ($content = $request->getContent()) { if ($content = $request->getContent()) {
$params = json_decode($content, true); $params = json_decode($content, true);
} }
if(! array_key_exists('code',$params)) if (!array_key_exists('code', $params))
$this->createNotFoundException(); $this->createNotFoundException();
$acc = $access->hasRole('accounting'); $acc = $access->hasRole('accounting');
if(!$acc) if (!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
'bid'=>$acc['bid'], 'bid' => $acc['bid'],
'year'=>$acc['year'], 'year' => $acc['year'],
'code'=>$params['code'] 'code' => $params['code']
]); ]);
if(!$doc) throw $this->createNotFoundException(); if (!$doc) throw $this->createNotFoundException();
$rows = []; $rows = [];
$rowsObj = $entityManager->getRepository(HesabdariRow::class)->findBy( $rowsObj = $entityManager->getRepository(HesabdariRow::class)->findBy(
['doc'=>$doc] ['doc' => $doc]
); );
foreach ($rowsObj as $item){ foreach ($rowsObj as $item) {
$temp=[]; $temp = [];
$temp['id'] = $item->getId(); $temp['id'] = $item->getId();
$temp['bs'] = $item->getBs(); $temp['bs'] = $item->getBs();
$temp['bd'] = $item->getBd(); $temp['bd'] = $item->getBd();
$temp['des'] = $item->getDes(); $temp['des'] = $item->getDes();
$temp['table'] = $item->getRef()->getName(); $temp['table'] = $item->getRef()->getName();
$temp['tableCode'] = $item->getRef()->getCode();
$temp['referral'] = $item->getReferral(); $temp['referral'] = $item->getReferral();
if($item->getPerson()){ if ($item->getPerson()) {
$temp['typeLabel'] = 'شخص'; $temp['typeLabel'] = 'شخص';
$temp['type'] = 'person'; $temp['type'] = 'person';
$temp['ref'] = $item->getPerson()->getNikeName(); $temp['ref'] = $item->getPerson()->getNikeName();
@ -78,11 +79,10 @@ class HesabdariController extends AbstractController
'address' => $item->getPerson()->getAddress(), 'address' => $item->getPerson()->getAddress(),
'des' => $item->getPerson()->getDes(), 'des' => $item->getPerson()->getDes(),
'shomaresabt' => $item->getperson()->getSabt(), 'shomaresabt' => $item->getperson()->getSabt(),
'codeeghtesadi' =>$item->getPerson()->getCodeeghtesadi(), 'codeeghtesadi' => $item->getPerson()->getCodeeghtesadi(),
'postalcode' => $item->getPerson()->getPostalCode() 'postalcode' => $item->getPerson()->getPostalCode()
]; ];
} } elseif ($item->getBank()) {
elseif($item->getBank()){
$temp['typeLabel'] = 'حسابهای بانکی'; $temp['typeLabel'] = 'حسابهای بانکی';
$temp['type'] = 'bank'; $temp['type'] = 'bank';
$temp['ref'] = $item->getBank()->getName(); $temp['ref'] = $item->getBank()->getName();
@ -100,17 +100,16 @@ class HesabdariController extends AbstractController
'mobileInternetBank' => $item->getBank()->getMobileInternetBank(), 'mobileInternetBank' => $item->getBank()->getMobileInternetBank(),
'code' => $item->getBank()->getCode(), 'code' => $item->getBank()->getCode(),
]; ];
} } elseif ($item->getCommodity()) {
elseif($item->getCommodity()){
$temp['typeLabel'] = 'موجودی کالا'; $temp['typeLabel'] = 'موجودی کالا';
$temp['type'] = 'commodity'; $temp['type'] = 'commodity';
$temp['ref'] = $item->getCommodity()->getName(); $temp['ref'] = $item->getCommodity()->getName();
$temp['refCode'] = $item->getCommodity()->getCode(); $temp['refCode'] = $item->getCommodity()->getCode();
$temp['count'] = $item->getCommdityCount(); $temp['count'] = $item->getCommdityCount();
if($doc->getType() == 'sell') if ($doc->getType() == 'sell')
$temp['unitPrice'] = $item->getBs()/$item->getCommdityCount(); $temp['unitPrice'] = $item->getBs() / $item->getCommdityCount();
elseif($doc->getType() == 'buy') elseif ($doc->getType() == 'buy')
$temp['unitPrice'] = $item->getBd()/$item->getCommdityCount(); $temp['unitPrice'] = $item->getBd() / $item->getCommdityCount();
$temp['commodity'] = [ $temp['commodity'] = [
'id' => $item->getCommodity()->getId(), 'id' => $item->getCommodity()->getId(),
'name' => $item->getCommodity()->getName(), 'name' => $item->getCommodity()->getName(),
@ -118,8 +117,7 @@ class HesabdariController extends AbstractController
'code' => $item->getCommodity()->getCode(), 'code' => $item->getCommodity()->getCode(),
'unit' => $item->getCommodity()->getUnit()->getName(), 'unit' => $item->getCommodity()->getUnit()->getName(),
]; ];
} } elseif ($item->getSalary()) {
elseif($item->getSalary()){
$temp['typeLabel'] = 'تنخواه گردان'; $temp['typeLabel'] = 'تنخواه گردان';
$temp['type'] = 'salary'; $temp['type'] = 'salary';
$temp['ref'] = $item->getSalary()->getName(); $temp['ref'] = $item->getSalary()->getName();
@ -130,8 +128,7 @@ class HesabdariController extends AbstractController
'des' => $item->getSalary()->getDes(), 'des' => $item->getSalary()->getDes(),
'code' => $item->getSalary()->getCode(), 'code' => $item->getSalary()->getCode(),
]; ];
} } elseif ($item->getCashdesk()) {
elseif($item->getCashdesk()){
$temp['typeLabel'] = 'صندوق'; $temp['typeLabel'] = 'صندوق';
$temp['type'] = 'cashdesk'; $temp['type'] = 'cashdesk';
$temp['ref'] = $item->getCashdesk()->getName(); $temp['ref'] = $item->getCashdesk()->getName();
@ -142,8 +139,7 @@ class HesabdariController extends AbstractController
'des' => $item->getCashdesk()->getDes(), 'des' => $item->getCashdesk()->getDes(),
'code' => $item->getCashdesk()->getCode(), 'code' => $item->getCashdesk()->getCode(),
]; ];
} } else {
else{
$temp['typeLabel'] = $item->getRef()->getName(); $temp['typeLabel'] = $item->getRef()->getName();
$temp['type'] = 'calc'; $temp['type'] = 'calc';
$temp['ref'] = $item->getRef()->getName(); $temp['ref'] = $item->getRef()->getName();
@ -153,7 +149,7 @@ class HesabdariController extends AbstractController
} }
//get related docs //get related docs
$rds = []; $rds = [];
foreach ($doc->getRelatedDocs() as $relatedDoc){ foreach ($doc->getRelatedDocs() as $relatedDoc) {
$temp = []; $temp = [];
$temp['amount'] = $relatedDoc->getAmount(); $temp['amount'] = $relatedDoc->getAmount();
$temp['des'] = $relatedDoc->getDes(); $temp['des'] = $relatedDoc->getDes();
@ -163,81 +159,79 @@ class HesabdariController extends AbstractController
$rds[] = $temp; $rds[] = $temp;
} }
return $this->json([ return $this->json([
'doc'=>JsonResp::SerializeHesabdariDoc($doc), 'doc' => JsonResp::SerializeHesabdariDoc($doc),
'rows'=>$rows, 'rows' => $rows,
'relatedDocs'=>$rds 'relatedDocs' => $rds
]); ]);
} }
#[Route('/api/accounting/search', name: 'app_accounting_search')] #[Route('/api/accounting/search', name: 'app_accounting_search')]
public function app_accounting_search(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse public function app_accounting_search(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{ {
$params = []; $params = [];
if ($content = $request->getContent()) { if ($content = $request->getContent()) {
$params = json_decode($content, true); $params = json_decode($content, true);
} }
if(! array_key_exists('type',$params)) if (!array_key_exists('type', $params))
$this->createNotFoundException(); $this->createNotFoundException();
$roll = ''; $roll = '';
if($params['type'] == 'person_receive' || $params['type'] == 'person_send') $roll='person'; if ($params['type'] == 'person_receive' || $params['type'] == 'person_send') $roll = 'person';
elseif($params['type'] == 'cost') $roll='cost'; elseif ($params['type'] == 'cost') $roll = 'cost';
elseif($params['type'] == 'income') $roll='income'; elseif ($params['type'] == 'income') $roll = 'income';
elseif($params['type'] == 'buy') $roll='buy'; elseif ($params['type'] == 'buy') $roll = 'buy';
elseif($params['type'] == 'rfbuy') $roll='plugAccproRfbuy'; elseif ($params['type'] == 'rfbuy') $roll = 'plugAccproRfbuy';
elseif($params['type'] == 'transfer') $roll='transfer'; elseif ($params['type'] == 'transfer') $roll = 'transfer';
elseif($params['type'] == 'sell') $roll='sell'; elseif ($params['type'] == 'sell') $roll = 'sell';
elseif($params['type'] == 'rfsell') $roll='plugAccproRfsell'; elseif ($params['type'] == 'rfsell') $roll = 'plugAccproRfsell';
elseif($params['type'] == 'all') $roll='accounting'; elseif ($params['type'] == 'all') $roll = 'accounting';
else else
$this->createNotFoundException(); $this->createNotFoundException();
$acc = $access->hasRole($roll); $acc = $access->hasRole($roll);
if(!$acc) if (!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
if($params['type'] == 'all'){ if ($params['type'] == 'all') {
$data = $entityManager->getRepository(HesabdariDoc::class)->findBy([ $data = $entityManager->getRepository(HesabdariDoc::class)->findBy([
'bid'=>$acc['bid'], 'bid' => $acc['bid'],
'year'=>$acc['year'], 'year' => $acc['year'],
],[ ], [
'id'=>'DESC' 'id' => 'DESC'
]);
} else {
$data = $entityManager->getRepository(HesabdariDoc::class)->findBy([
'bid' => $acc['bid'],
'year' => $acc['year'],
'type' => $params['type']
], [
'id' => 'DESC'
]); ]);
} }
else{ $dataTemp = [];
$data = $entityManager->getRepository(HesabdariDoc::class)->findBy([ foreach ($data as $item) {
'bid'=>$acc['bid'],
'year'=>$acc['year'],
'type'=>$params['type']
],[
'id'=>'DESC'
]);
}
$dataTemp =[];
foreach ($data as $item){
$temp = [ $temp = [
'id'=>$item->getId(), 'id' => $item->getId(),
'dateSubmit'=>$item->getDateSubmit(), 'dateSubmit' => $item->getDateSubmit(),
'date'=>$item->getDate(), 'date' => $item->getDate(),
'type'=>$item->getType(), 'type' => $item->getType(),
'code'=>$item->getCode(), 'code' => $item->getCode(),
'des'=>$item->getDes(), 'des' => $item->getDes(),
'amount'=>$item->getAmount(), 'amount' => $item->getAmount(),
'submitter'=> $item->getSubmitter()->getFullName(), 'submitter' => $item->getSubmitter()->getFullName(),
]; ];
if($params['type'] == 'rfsell' || $params['type'] == 'rfbuy' || $params['type'] == 'buy' || $params['type'] == 'sell'){ if ($params['type'] == 'rfsell' || $params['type'] == 'rfbuy' || $params['type'] == 'buy' || $params['type'] == 'sell') {
$mainRow = $entityManager->getRepository(HesabdariRow::class)->getNotEqual($item,'person'); $mainRow = $entityManager->getRepository(HesabdariRow::class)->getNotEqual($item, 'person');
$temp['person'] = ''; $temp['person'] = '';
if($mainRow) if ($mainRow)
$temp['person'] = $mainRow->getPerson()->getNikename(); $temp['person'] = $mainRow->getPerson()->getNikename();
} }
//get status of doc //get status of doc
$temp['status'] = 'تسویه نشده'; $temp['status'] = 'تسویه نشده';
$pays = 0; $pays = 0;
foreach ($item->getRelatedDocs() as $relatedDoc){ foreach ($item->getRelatedDocs() as $relatedDoc) {
$pays += $relatedDoc->getAmount(); $pays += $relatedDoc->getAmount();
} }
if($item->getAmount() <= $pays) if ($item->getAmount() <= $pays)
$temp['status'] = 'تسویه شده'; $temp['status'] = 'تسویه شده';
$dataTemp[] = $temp; $dataTemp[] = $temp;
@ -249,51 +243,52 @@ class HesabdariController extends AbstractController
* @throws \ReflectionException * @throws \ReflectionException
*/ */
#[Route('/api/accounting/insert', name: 'app_accounting_insert')] #[Route('/api/accounting/insert', name: 'app_accounting_insert')]
public function app_accounting_insert(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,Jdate $jdate): JsonResponse public function app_accounting_insert(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, Jdate $jdate): JsonResponse
{ {
$params = []; $params = [];
if ($content = $request->getContent()) { if ($content = $request->getContent()) {
$params = json_decode($content, true); $params = json_decode($content, true);
} }
if(! array_key_exists('type',$params)) if (!array_key_exists('type', $params))
$this->createNotFoundException(); $this->createNotFoundException();
$roll = ''; $roll = '';
if($params['type'] == 'person_receive' || $params['type'] == 'person_send') $roll='person'; if ($params['type'] == 'person_receive' || $params['type'] == 'person_send') $roll = 'person';
elseif ($params['type'] == 'sell_receive') $roll = 'sell';
elseif ($params['type'] == 'buy_send') $roll = 'buy';
else else
$roll = $params['type']; $roll = $params['type'];
$acc = $access->hasRole($roll); $acc = $access->hasRole($roll);
if(!$acc) if (!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
if(!array_key_exists('rows',$params) || count($params['rows']) < 2) if (!array_key_exists('rows', $params) || count($params['rows']) < 2)
throw $this->createNotFoundException('rows is to short'); throw $this->createNotFoundException('rows is to short');
if(!array_key_exists('date',$params) || !array_key_exists('des',$params)) if (!array_key_exists('date', $params) || !array_key_exists('des', $params))
throw $this->createNotFoundException('some params mistake'); throw $this->createNotFoundException('some params mistake');
if(array_key_exists('update',$params) && $params['update'] != ''){ if (array_key_exists('update', $params) && $params['update'] != '') {
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
'bid'=>$acc['bid'], 'bid' => $acc['bid'],
'year'=>$acc['year'], 'year' => $acc['year'],
'code'=>$params['update'] 'code' => $params['update']
]); ]);
if(!$doc) throw $this->createNotFoundException('document not found.'); if (!$doc) throw $this->createNotFoundException('document not found.');
$doc->setDes($params['des']); $doc->setDes($params['des']);
$doc->setDate($params['date']); $doc->setDate($params['date']);
$doc->setMoney($acc['bid']->getMoney()); $doc->setMoney($acc['bid']->getMoney());
if(array_key_exists('refData',$params)) if (array_key_exists('refData', $params))
$doc->setRefData($params['refData']); $doc->setRefData($params['refData']);
if(array_key_exists('plugin',$params)) if (array_key_exists('plugin', $params))
$doc->setPlugin($params['plugin']); $doc->setPlugin($params['plugin']);
$entityManager->persist($doc); $entityManager->persist($doc);
$entityManager->flush(); $entityManager->flush();
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
'doc'=>$doc 'doc' => $doc
]); ]);
foreach ($rows as $row) foreach ($rows as $row)
$entityManager->remove($row); $entityManager->remove($row);
} } else {
else{
$doc = new HesabdariDoc(); $doc = new HesabdariDoc();
$doc->setBid($acc['bid']); $doc->setBid($acc['bid']);
$doc->setYear($acc['year']); $doc->setYear($acc['year']);
@ -303,19 +298,19 @@ class HesabdariController extends AbstractController
$doc->setDate($params['date']); $doc->setDate($params['date']);
$doc->setSubmitter($this->getUser()); $doc->setSubmitter($this->getUser());
$doc->setMoney($acc['bid']->getMoney()); $doc->setMoney($acc['bid']->getMoney());
$doc->setCode($provider->getAccountingCode($acc['bid'],'accounting')); $doc->setCode($provider->getAccountingCode($acc['bid'], 'accounting'));
if(array_key_exists('refData',$params)) if (array_key_exists('refData', $params))
$doc->setRefData($params['refData']); $doc->setRefData($params['refData']);
if(array_key_exists('plugin',$params)) if (array_key_exists('plugin', $params))
$doc->setPlugin($params['plugin']); $doc->setPlugin($params['plugin']);
$entityManager->persist($doc); $entityManager->persist($doc);
$entityManager->flush(); $entityManager->flush();
} }
//add document to related docs //add document to related docs
if(array_key_exists('related',$params)){ if (array_key_exists('related', $params)) {
$relatedDoc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy(['code'=>$params['related'],'bid'=>$doc->getBid()]); $relatedDoc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy(['code' => $params['related'], 'bid' => $doc->getBid()]);
if($relatedDoc){ if ($relatedDoc) {
$relatedDoc->addRelatedDoc($doc); $relatedDoc->addRelatedDoc($doc);
$entityManager->persist($relatedDoc); $entityManager->persist($relatedDoc);
$entityManager->flush(); $entityManager->flush();
@ -323,9 +318,9 @@ class HesabdariController extends AbstractController
} }
$amount = 0; $amount = 0;
foreach ($params['rows'] as $row){ foreach ($params['rows'] as $row) {
$row['bs'] = str_replace(',','',$row['bs']); $row['bs'] = str_replace(',', '', $row['bs']);
$row['bd'] = str_replace(',','',$row['bd']); $row['bd'] = str_replace(',', '', $row['bd']);
$hesabdariRow = new HesabdariRow(); $hesabdariRow = new HesabdariRow();
$hesabdariRow->setBid($acc['bid']); $hesabdariRow->setBid($acc['bid']);
@ -334,26 +329,25 @@ class HesabdariController extends AbstractController
$hesabdariRow->setBs($row['bs']); $hesabdariRow->setBs($row['bs']);
$hesabdariRow->setBd($row['bd']); $hesabdariRow->setBd($row['bd']);
$ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy([ $ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy([
'code'=>$row['table'] 'code' => $row['table']
]); ]);
$hesabdariRow->setRef($ref); $hesabdariRow->setRef($ref);
$entityManager->persist($hesabdariRow); $entityManager->persist($hesabdariRow);
if(array_key_exists('referral',$row)) if (array_key_exists('referral', $row))
$hesabdariRow->setReferral($row['referral']); $hesabdariRow->setReferral($row['referral']);
$amount += $row['bs']; $amount += $row['bs'];
//check is type is person //check is type is person
if($row['type'] == 'person'){ if ($row['type'] == 'person') {
$person = $entityManager->getRepository(Person::class)->find($row['id']); $person = $entityManager->getRepository(Person::class)->find($row['id']);
if(!$person) throw $this->createNotFoundException('person not found'); if (!$person) throw $this->createNotFoundException('person not found');
elseif ($person->getBid()->getId() != $acc['bid']->getId()) throw $this->createAccessDeniedException('person is not in this business'); elseif ($person->getBid()->getId() != $acc['bid']->getId()) throw $this->createAccessDeniedException('person is not in this business');
$hesabdariRow->setPerson($person); $hesabdariRow->setPerson($person);
} } elseif ($row['type'] == 'cheque') {
elseif($row['type'] == 'cheque'){
$person = $entityManager->getRepository(Person::class)->findOneBy([ $person = $entityManager->getRepository(Person::class)->findOneBy([
'bid'=> $acc['bid'], 'bid' => $acc['bid'],
'id'=>$row['chequeOwner'] 'id' => $row['chequeOwner']
]); ]);
$cheque = new Cheque(); $cheque = new Cheque();
echo $hesabdariRow->getRef(); echo $hesabdariRow->getRef();
@ -366,13 +360,13 @@ class HesabdariController extends AbstractController
$cheque->setSayadNum($row['chequeSayadNum']); $cheque->setSayadNum($row['chequeSayadNum']);
$cheque->setDateSubmit(time()); $cheque->setDateSubmit(time());
$cheque->setDes($row['des']); $cheque->setDes($row['des']);
$dateArray = explode('-',$row['chequeDate']); $dateArray = explode('-', $row['chequeDate']);
$dateGre = strtotime($jdate->jalali_to_gregorian($dateArray['0'],$dateArray['1'],$dateArray['2'],'/')); $dateGre = strtotime($jdate->jalali_to_gregorian($dateArray['0'], $dateArray['1'], $dateArray['2'], '/'));
$cheque->setDateStamp($dateGre); $cheque->setDateStamp($dateGre);
$cheque->setPerson($person); $cheque->setPerson($person);
$cheque->setRef($entityManager->getRepository(HesabdariTable::class)->findOneBy(['code'=>$row['table']])); $cheque->setRef($entityManager->getRepository(HesabdariTable::class)->findOneBy(['code' => $row['table']]));
$cheque->setType($row['chequeType']); $cheque->setType($row['chequeType']);
if($cheque->getType() == 'input') if ($cheque->getType() == 'input')
$cheque->setAmount($hesabdariRow->getBd()); $cheque->setAmount($hesabdariRow->getBd());
else else
$cheque->setAmount($hesabdariRow->getBs()); $cheque->setAmount($hesabdariRow->getBs());
@ -382,233 +376,226 @@ class HesabdariController extends AbstractController
$entityManager->persist($cheque); $entityManager->persist($cheque);
$entityManager->flush(); $entityManager->flush();
$hesabdariRow->setCheque($cheque); $hesabdariRow->setCheque($cheque);
} } elseif ($row['type'] == 'bank') {
elseif ($row['type'] == 'bank'){
$bank = $entityManager->getRepository(BankAccount::class)->find($row['id']); $bank = $entityManager->getRepository(BankAccount::class)->find($row['id']);
if(!$bank) throw $this->createNotFoundException('bank not found'); if (!$bank) throw $this->createNotFoundException('bank not found');
elseif ($bank->getBid()->getId() != $acc['bid']->getId()) throw $this->createAccessDeniedException('bank is not in this business'); elseif ($bank->getBid()->getId() != $acc['bid']->getId()) throw $this->createAccessDeniedException('bank is not in this business');
$hesabdariRow->setBank($bank); $hesabdariRow->setBank($bank);
} } elseif ($row['type'] == 'salary') {
elseif ($row['type'] == 'salary'){
$salary = $entityManager->getRepository(Salary::class)->find($row['id']); $salary = $entityManager->getRepository(Salary::class)->find($row['id']);
if(!$salary) throw $this->createNotFoundException('salary not found'); if (!$salary) throw $this->createNotFoundException('salary not found');
elseif ($salary->getBid()->getId() != $acc['bid']->getId()) throw $this->createAccessDeniedException('bank is not in this business'); elseif ($salary->getBid()->getId() != $acc['bid']->getId()) throw $this->createAccessDeniedException('bank is not in this business');
$hesabdariRow->setSalary($salary); $hesabdariRow->setSalary($salary);
} } elseif ($row['type'] == 'cashdesk') {
elseif ($row['type'] == 'cashdesk'){
$cashdesk = $entityManager->getRepository(Cashdesk::class)->find($row['id']); $cashdesk = $entityManager->getRepository(Cashdesk::class)->find($row['id']);
if(!$cashdesk) throw $this->createNotFoundException('cashdesk not found'); if (!$cashdesk) throw $this->createNotFoundException('cashdesk not found');
elseif ($cashdesk->getBid()->getId() != $acc['bid']->getId()) throw $this->createAccessDeniedException('bank is not in this business'); elseif ($cashdesk->getBid()->getId() != $acc['bid']->getId()) throw $this->createAccessDeniedException('bank is not in this business');
$hesabdariRow->setCashdesk($cashdesk); $hesabdariRow->setCashdesk($cashdesk);
} } elseif ($row['type'] == 'commodity') {
elseif ($row['type'] == 'commodity'){ $row['count'] = str_replace(',', '', $row['count']);
$row['count'] = str_replace(',','',$row['count']);
$commodity = $entityManager->getRepository(Commodity::class)->find($row['commodity']['id']); $commodity = $entityManager->getRepository(Commodity::class)->find($row['commodity']['id']);
if(!$commodity) throw $this->createNotFoundException('commodity not found'); if (!$commodity) throw $this->createNotFoundException('commodity not found');
elseif ($commodity->getBid()->getId() != $acc['bid']->getId()) throw $this->createAccessDeniedException('$commodity is not in this business'); elseif ($commodity->getBid()->getId() != $acc['bid']->getId()) throw $this->createAccessDeniedException('$commodity is not in this business');
$hesabdariRow->setCommodity($commodity); $hesabdariRow->setCommodity($commodity);
$hesabdariRow->setCommdityCount($row['count']); $hesabdariRow->setCommdityCount($row['count']);
} }
if(array_key_exists('plugin',$row)) if (array_key_exists('plugin', $row))
$hesabdariRow->setPlugin($row['plugin']); $hesabdariRow->setPlugin($row['plugin']);
if(array_key_exists('refData',$row)) if (array_key_exists('refData', $row))
$hesabdariRow->setRefData($row['refData']); $hesabdariRow->setRefData($row['refData']);
$hesabdariRow->setDes($row['des']); $hesabdariRow->setDes($row['des']);
$entityManager->persist($hesabdariRow); $entityManager->persist($hesabdariRow);
$entityManager->flush(); $entityManager->flush();
} }
$doc->setAmount($amount); $doc->setAmount($amount);
$entityManager->persist($doc); $entityManager->persist($doc);
$entityManager->flush(); $entityManager->flush();
$log->insert( $log->insert(
'حسابداری','سند حسابداری شماره ' . $doc->getCode() . ' ثبت / ویرایش شد.', 'حسابداری',
'سند حسابداری شماره ' . $doc->getCode() . ' ثبت / ویرایش شد.',
$this->getUser(), $this->getUser(),
$request->headers->get('activeBid'), $request->headers->get('activeBid'),
$doc $doc
); );
return $this->json([ return $this->json([
'result'=>1, 'result' => 1,
'doc'=>$provider->Entity2Array($doc,0) 'doc' => $provider->Entity2Array($doc, 0)
]); ]);
} }
#[Route('/api/accounting/remove', name: 'app_accounting_remove_doc')] #[Route('/api/accounting/remove', name: 'app_accounting_remove_doc')]
public function app_accounting_remove_doc(Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse public function app_accounting_remove_doc(Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{ {
$params = []; $params = [];
if ($content = $request->getContent()) { if ($content = $request->getContent()) {
$params = json_decode($content, true); $params = json_decode($content, true);
} }
if(! array_key_exists('code',$params)) if (!array_key_exists('code', $params))
$this->createNotFoundException(); $this->createNotFoundException();
$doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([
'code'=>$params['code'], 'code' => $params['code'],
'bid'=>$request->headers->get('activeBid') 'bid' => $request->headers->get('activeBid')
]); ]);
if(!$doc) throw $this->createNotFoundException(); if (!$doc) throw $this->createNotFoundException();
$roll = ''; $roll = '';
if($doc->getType() == 'person_receive' || $doc->getType() == 'person_send') if ($doc->getType() == 'person_receive' || $doc->getType() == 'person_send') $roll = 'person';
$roll = 'person'; elseif ($doc->getType() == 'sell_receive') $roll = 'sell';
elseif ($doc->getType() == 'buy_send') $roll = 'buy';
else else
$roll = $doc->getType(); $roll = $doc->getType();
$acc = $access->hasRole($roll); $acc = $access->hasRole($roll);
if(!$acc) if (!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
'doc'=>$doc 'doc' => $doc
]); ]);
if($doc->getPlugin() == 'plugNoghreOrder'){ if ($doc->getPlugin() == 'plugNoghreOrder') {
$order = $entityManager->getRepository(PlugNoghreOrder::class)->findOneBy([ $order = $entityManager->getRepository(PlugNoghreOrder::class)->findOneBy([
'doc'=>$doc 'doc' => $doc
]); ]);
if($order) if ($order)
$entityManager->remove($order); $entityManager->remove($order);
} }
//check wallet online transactions //check wallet online transactions
$tempPays = $entityManager->getRepository(PayInfoTemp::class)->findOneBy(['doc'=>$doc]); $tempPays = $entityManager->getRepository(PayInfoTemp::class)->findOneBy(['doc' => $doc]);
if($tempPays){ if ($tempPays) {
//doc has transaction //doc has transaction
return $this->json([ return $this->json([
'result'=>2, 'result' => 2,
'message'=>'سند به دلیل داشتن تراکنش پرداخت آنلاین قابل حذف نیست.' 'message' => 'سند به دلیل داشتن تراکنش پرداخت آنلاین قابل حذف نیست.'
]); ]);
} }
//check storeroom tickets //check storeroom tickets
$tickets = $entityManager->getRepository(StoreroomTicket::class)->findBy(['doc'=>$doc]); $tickets = $entityManager->getRepository(StoreroomTicket::class)->findBy(['doc' => $doc]);
foreach ($tickets as $ticket) foreach ($tickets as $ticket)
$entityManager->remove($ticket); $entityManager->remove($ticket);
//remove rows and check sub systems //remove rows and check sub systems
foreach ($rows as $row){ foreach ($rows as $row) {
if($row->getCheque()){ if ($row->getCheque()) {
if($row->getCheque()->isLocked()){ if ($row->getCheque()->isLocked()) {
//doc has transaction //doc has transaction
return $this->json([ return $this->json([
'result'=>2, 'result' => 2,
'message'=>'سند به دلیل داشتن تراکنش مرتبط با چک بانکی قابل حذف نیست.' 'message' => 'سند به دلیل داشتن تراکنش مرتبط با چک بانکی قابل حذف نیست.'
]); ]);
} }
$log->insert('بانکداری','چک شماره شماره ' . $row->getCheque()->getNumber() . ' حذف شد.',$this->getUser(),$request->headers->get('activeBid')); $log->insert('بانکداری', 'چک شماره شماره ' . $row->getCheque()->getNumber() . ' حذف شد.', $this->getUser(), $request->headers->get('activeBid'));
$entityManager->remove($row->getCheque()); $entityManager->remove($row->getCheque());
} }
$entityManager->remove($row); $entityManager->remove($row);
} }
foreach ($doc->getRelatedDocs() as $relatedDoc){ foreach ($doc->getRelatedDocs() as $relatedDoc) {
if($relatedDoc->getType() != 'walletPay'){ if ($relatedDoc->getType() != 'walletPay') {
$items = $entityManager->getRepository(HesabdariRow::class)->findBy(['doc'=>$relatedDoc]); $items = $entityManager->getRepository(HesabdariRow::class)->findBy(['doc' => $relatedDoc]);
foreach ($items as $item) foreach ($items as $item)
$entityManager->remove($item); $entityManager->remove($item);
$entityManager->remove($relatedDoc); $entityManager->remove($relatedDoc);
$log->insert('حسابداری','سند حسابداری شماره ' . $relatedDoc->getCode() . ' حذف شد.',$this->getUser(),$request->headers->get('activeBid')); $log->insert('حسابداری', 'سند حسابداری شماره ' . $relatedDoc->getCode() . ' حذف شد.', $this->getUser(), $request->headers->get('activeBid'));
} }
} }
//delete logs from documents //delete logs from documents
$logs = $entityManager->getRepository(EntityLog::class)->findBy(['doc'=>$doc]); $logs = $entityManager->getRepository(EntityLog::class)->findBy(['doc' => $doc]);
foreach($logs as $item){ foreach ($logs as $item) {
$item->setDoc(null); $item->setDoc(null);
$entityManager->persist($item); $entityManager->persist($item);
$entityManager->flush(); $entityManager->flush();
} }
$entityManager->remove($doc); $entityManager->remove($doc);
$entityManager->flush(); $entityManager->flush();
$log->insert('حسابداری','سند حسابداری شماره ' . $doc->getCode() . ' حذف شد.',$this->getUser(),$request->headers->get('activeBid')); $log->insert('حسابداری', 'سند حسابداری شماره ' . $doc->getCode() . ' حذف شد.', $this->getUser(), $request->headers->get('activeBid'));
return $this->json(['result'=>1]); return $this->json(['result' => 1]);
} }
#[Route('/api/accounting/rows/search', name: 'app_accounting_rows_search')] #[Route('/api/accounting/rows/search', name: 'app_accounting_rows_search')]
public function app_accounting_rows_search(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse public function app_accounting_rows_search(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{ {
$params = []; $params = [];
if ($content = $request->getContent()) { if ($content = $request->getContent()) {
$params = json_decode($content, true); $params = json_decode($content, true);
} }
if(! array_key_exists('type',$params)) if (!array_key_exists('type', $params))
$this->createNotFoundException(); $this->createNotFoundException();
$roll = ''; $roll = '';
if($params['type'] == 'person') $roll='person'; if ($params['type'] == 'person') $roll = 'person';
elseif($params['type'] == 'all') $roll='accounting'; elseif ($params['type'] == 'all') $roll = 'accounting';
else else
$this->createNotFoundException(); $this->createNotFoundException();
$acc = $access->hasRole($roll); $acc = $access->hasRole($roll);
if(!$acc) if (!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
if($params['type'] == 'person'){ if ($params['type'] == 'person') {
$person = $entityManager->getRepository(Person::class)->findOneBy([ $person = $entityManager->getRepository(Person::class)->findOneBy([
'bid'=>$acc['bid'], 'bid' => $acc['bid'],
'code'=>$params['id'], 'code' => $params['id'],
]); ]);
if(!$person) if (!$person)
throw $this->createNotFoundException(); throw $this->createNotFoundException();
$data = $entityManager->getRepository(HesabdariRow::class)->findBy([ $data = $entityManager->getRepository(HesabdariRow::class)->findBy([
'person'=> $person, 'person' => $person,
],[ ], [
'id'=>'DESC' 'id' => 'DESC'
]); ]);
} } elseif ($params['type'] == 'bank') {
elseif($params['type'] == 'bank'){
$bank = $entityManager->getRepository(BankAccount::class)->findOneBy([ $bank = $entityManager->getRepository(BankAccount::class)->findOneBy([
'bid'=>$acc['bid'], 'bid' => $acc['bid'],
'code'=>$params['id'], 'code' => $params['id'],
]); ]);
if(!$bank) if (!$bank)
throw $this->createNotFoundException(); throw $this->createNotFoundException();
$data = $entityManager->getRepository(HesabdariRow::class)->findBy([ $data = $entityManager->getRepository(HesabdariRow::class)->findBy([
'bank'=> $bank, 'bank' => $bank,
],[ ], [
'id'=>'DESC' 'id' => 'DESC'
]); ]);
} } elseif ($params['type'] == 'cashdesk') {
elseif($params['type'] == 'cashdesk'){
$cashdesk = $entityManager->getRepository(Cashdesk::class)->findOneBy([ $cashdesk = $entityManager->getRepository(Cashdesk::class)->findOneBy([
'bid'=>$acc['bid'], 'bid' => $acc['bid'],
'code'=>$params['id'], 'code' => $params['id'],
]); ]);
if(!$cashdesk) if (!$cashdesk)
throw $this->createNotFoundException(); throw $this->createNotFoundException();
$data = $entityManager->getRepository(HesabdariRow::class)->findBy([ $data = $entityManager->getRepository(HesabdariRow::class)->findBy([
'cashdesk'=> $cashdesk, 'cashdesk' => $cashdesk,
],[ ], [
'id'=>'DESC' 'id' => 'DESC'
]); ]);
} } elseif ($params['type'] == 'salary') {
elseif($params['type'] == 'salary'){
$salary = $entityManager->getRepository(Salary::class)->findOneBy([ $salary = $entityManager->getRepository(Salary::class)->findOneBy([
'bid'=>$acc['bid'], 'bid' => $acc['bid'],
'code'=>$params['id'], 'code' => $params['id'],
]); ]);
if(!$salary) if (!$salary)
throw $this->createNotFoundException(); throw $this->createNotFoundException();
$data = $entityManager->getRepository(HesabdariRow::class)->findBy([ $data = $entityManager->getRepository(HesabdariRow::class)->findBy([
'salary'=> $salary, 'salary' => $salary,
],[ ], [
'id'=>'DESC' 'id' => 'DESC'
]); ]);
} }
$dataTemp =[]; $dataTemp = [];
foreach ($data as $item){ foreach ($data as $item) {
$temp = [ $temp = [
'id'=>$item->getId(), 'id' => $item->getId(),
'dateSubmit'=>$item->getDoc()->getDateSubmit(), 'dateSubmit' => $item->getDoc()->getDateSubmit(),
'date'=>$item->getDoc()->getDate(), 'date' => $item->getDoc()->getDate(),
'type'=>$item->getDoc()->getType(), 'type' => $item->getDoc()->getType(),
'ref'=>$item->getRef()->getName(), 'ref' => $item->getRef()->getName(),
'des'=>$item->getDes(), 'des' => $item->getDes(),
'bs'=>$item->getBs(), 'bs' => $item->getBs(),
'bd'=>$item->getBd(), 'bd' => $item->getBd(),
'code'=>$item->getDoc()->getCode(), 'code' => $item->getDoc()->getCode(),
'submitter'=> $item->getDoc()->getSubmitter()->getFullName() 'submitter' => $item->getDoc()->getSubmitter()->getFullName()
]; ];
$dataTemp[] = $temp; $dataTemp[] = $temp;
} }
@ -616,24 +603,23 @@ class HesabdariController extends AbstractController
} }
#[Route('/api/accounting/table/get', name: 'app_accounting_table_get')] #[Route('/api/accounting/table/get', name: 'app_accounting_table_get')]
public function app_accounting_table_get(Jdate $jdate,Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse public function app_accounting_table_get(Jdate $jdate, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{ {
$acc = $access->hasRole('accounting'); $acc = $access->hasRole('accounting');
if(!$acc) if (!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$temp =[]; $temp = [];
$nodes = $entityManager->getRepository(HesabdariTable::class)->findAll(); $nodes = $entityManager->getRepository(HesabdariTable::class)->findAll();
foreach ($nodes as $node){ foreach ($nodes as $node) {
if($this->hasChild($entityManager,$node)){ if ($this->hasChild($entityManager, $node)) {
$temp[$node->getCode()]=[ $temp[$node->getCode()] = [
'text'=>$node->getName(), 'text' => $node->getName(),
'children'=>$this->getChildsLabel($entityManager,$node) 'children' => $this->getChildsLabel($entityManager, $node)
]; ];
} } else {
else{ $temp[$node->getCode()] = [
$temp[$node->getCode()]=[ 'text' => $node->getName(),
'text'=>$node->getName(),
]; ];
} }
} }
@ -641,30 +627,30 @@ class HesabdariController extends AbstractController
} }
#[Route('/api/accounting/table/childs/{type}', name: 'app_accounting_table_childs')] #[Route('/api/accounting/table/childs/{type}', name: 'app_accounting_table_childs')]
public function app_accounting_table_childs(string $type,Jdate $jdate,Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse public function app_accounting_table_childs(string $type, Jdate $jdate, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{ {
$acc = $access->hasRole($type); $acc = $access->hasRole($type);
if(!$acc) if (!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
if($type == 'cost'){ if ($type == 'cost') {
$cost= $entityManager->getRepository(HesabdariTable::class)->findOneBy(['code'=>67]); $cost = $entityManager->getRepository(HesabdariTable::class)->findOneBy(['code' => 67]);
return $this->json($this->getChilds($entityManager,$cost)); return $this->json($this->getChilds($entityManager, $cost));
} } elseif ($type == 'income') {
elseif($type == 'income'){ $income = $entityManager->getRepository(HesabdariTable::class)->findOneBy(['code' => 56]);
$income= $entityManager->getRepository(HesabdariTable::class)->findOneBy(['code'=>56]); return $this->json($this->getChilds($entityManager, $income));
return $this->json($this->getChilds($entityManager,$income));
} }
return $this->json([]); return $this->json([]);
} }
private function getChildsLabel(EntityManagerInterface $entityManager, mixed $node){ private function getChildsLabel(EntityManagerInterface $entityManager, mixed $node)
{
$childs = $entityManager->getRepository(HesabdariTable::class)->findBy([ $childs = $entityManager->getRepository(HesabdariTable::class)->findBy([
'upper'=>$node 'upper' => $node
]); ]);
$temp = []; $temp = [];
foreach ($childs as $child){ foreach ($childs as $child) {
$temp[] = $child->getCode(); $temp[] = $child->getCode();
} }
return $temp; return $temp;
@ -672,37 +658,35 @@ class HesabdariController extends AbstractController
private function hasChild(EntityManagerInterface $entityManager, mixed $node) private function hasChild(EntityManagerInterface $entityManager, mixed $node)
{ {
if(count($entityManager->getRepository(HesabdariTable::class)->findBy([ if (count($entityManager->getRepository(HesabdariTable::class)->findBy([
'upper'=>$node 'upper' => $node
]))!= 0) ])) != 0)
return true; return true;
return false; return false;
} }
private function getChilds(EntityManagerInterface $entityManager, mixed $node){ private function getChilds(EntityManagerInterface $entityManager, mixed $node)
{
$childs = $entityManager->getRepository(HesabdariTable::class)->findBy([ $childs = $entityManager->getRepository(HesabdariTable::class)->findBy([
'upper'=>$node 'upper' => $node
]); ]);
$temp = []; $temp = [];
foreach ($childs as $child){ foreach ($childs as $child) {
if ($child->getType() == 'calc'){ if ($child->getType() == 'calc') {
if($this->hasChild($entityManager,$child)){ if ($this->hasChild($entityManager, $child)) {
$temp[]=[ $temp[] = [
'id'=>$child->getCode(), 'id' => $child->getCode(),
'label'=>$child->getName(), 'label' => $child->getName(),
'children'=>$this->getChilds($entityManager,$child) 'children' => $this->getChilds($entityManager, $child)
]; ];
} } else {
else{ $temp[] = [
$temp[]=[ 'id' => $child->getCode(),
'id'=>$child->getCode(), 'label' => $child->getName(),
'label'=>$child->getName(),
]; ];
} }
} }
} }
return $temp; return $temp;
} }
} }

View file

@ -17,21 +17,21 @@ use Symfony\Component\Routing\Annotation\Route;
class SalaryController extends AbstractController class SalaryController extends AbstractController
{ {
#[Route('/api/salary/list', name: 'app_salary_list')] #[Route('/api/salary/list', name: 'app_salary_list')]
public function app_salary_list(Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse public function app_salary_list(Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{ {
//باگ دارد تمام سال مالی برگشت داده می شود //باگ دارد تمام سال مالی برگشت داده می شود
if(!$access->hasRole('salary')) if (!$access->hasRole('salary'))
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$datas = $entityManager->getRepository(Salary::class)->findBy([ $datas = $entityManager->getRepository(Salary::class)->findBy([
'bid'=>$request->headers->get('activeBid') 'bid' => $request->headers->get('activeBid')
]); ]);
foreach($datas as $data){ foreach ($datas as $data) {
$bs = 0; $bs = 0;
$bd = 0; $bd = 0;
$items = $entityManager->getRepository(HesabdariRow::class)->findBy([ $items = $entityManager->getRepository(HesabdariRow::class)->findBy([
'salary'=>$data 'salary' => $data
]); ]);
foreach ($items as $item){ foreach ($items as $item) {
$bs += $item->getBs(); $bs += $item->getBs();
$bd += $item->getBd(); $bd += $item->getBd();
} }
@ -41,49 +41,48 @@ class SalaryController extends AbstractController
} }
#[Route('/api/salary/info/{code}', name: 'app_salary_info')] #[Route('/api/salary/info/{code}', name: 'app_salary_info')]
public function app_salary_info($code,Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse public function app_salary_info($code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse
{ {
$acc = $access->hasRole('salary'); $acc = $access->hasRole('salary');
if(!$acc) if (!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$data = $entityManager->getRepository(Salary::class)->findOneBy([ $data = $entityManager->getRepository(Salary::class)->findOneBy([
'bid'=>$acc['bid'], 'bid' => $acc['bid'],
'code'=>$code 'code' => $code
]); ]);
return $this->json($data); return $this->json($data);
} }
#[Route('/api/salary/mod/{code}', name: 'app_salary_mod')] #[Route('/api/salary/mod/{code}', name: 'app_salary_mod')]
public function app_salary_mod(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse public function app_salary_mod(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse
{ {
$acc = $access->hasRole('salary'); $acc = $access->hasRole('salary');
if(!$acc) if (!$acc)
throw $this->createAccessDeniedException(); throw $this->createAccessDeniedException();
$params = []; $params = [];
if ($content = $request->getContent()) { if ($content = $request->getContent()) {
$params = json_decode($content, true); $params = json_decode($content, true);
} }
if(!array_key_exists('name',$params)) if (!array_key_exists('name', $params))
return $this->json(['result'=>-1]); return $this->json(['result' => -1]);
if(count_chars(trim($params['name'])) == 0) if (count_chars(trim($params['name'])) == 0)
return $this->json(['result'=>3]); return $this->json(['result' => 3]);
if($code == 0){ if ($code == 0) {
$data = $entityManager->getRepository(Salary::class)->findOneBy([ $data = $entityManager->getRepository(Salary::class)->findOneBy([
'name'=>$params['name'], 'name' => $params['name'],
'bid' =>$acc['bid'] 'bid' => $acc['bid']
]); ]);
//check exist before //check exist before
if($data) if ($data)
return $this->json(['result'=>2]); return $this->json(['result' => 2]);
$data = new Salary(); $data = new Salary();
$data->setCode($provider->getAccountingCode($request->headers->get('activeBid'),'salary')); $data->setCode($provider->getAccountingCode($request->headers->get('activeBid'), 'salary'));
} } else {
else{
$data = $entityManager->getRepository(Salary::class)->findOneBy([ $data = $entityManager->getRepository(Salary::class)->findOneBy([
'bid'=>$acc['bid'], 'bid' => $acc['bid'],
'code'=>$code 'code' => $code
]); ]);
if(!$data) if (!$data)
throw $this->createNotFoundException(); throw $this->createNotFoundException();
} }
$data->setBid($acc['bid']); $data->setBid($acc['bid']);
@ -91,7 +90,28 @@ class SalaryController extends AbstractController
$data->setDes($params['des']); $data->setDes($params['des']);
$entityManager->persist($data); $entityManager->persist($data);
$entityManager->flush(); $entityManager->flush();
$log->insert('بانک','تنخواه گردان با نام ' . $params['name'] . ' افزوده/ویرایش شد.',$this->getUser(),$request->headers->get('activeBid')); $log->insert('بانک', 'تنخواه گردان با نام ' . $params['name'] . ' افزوده/ویرایش شد.', $this->getUser(), $request->headers->get('activeBid'));
return $this->json(['result' => 1]);
}
#[Route('/api/salary/delete/{code}', name: 'app_salary_delete')]
public function app_salary_delete(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse
{
$acc = $access->hasRole('salary');
if (!$acc)
throw $this->createAccessDeniedException();
$salary = $entityManager->getRepository(Salary::class)->findOneBy(['bid' => $acc['bid'], 'code' => $code]);
if (!$salary)
throw $this->createNotFoundException();
//check accounting docs
$rows = $entityManager->getRepository(HesabdariRow::class)->findby(['bid' => $acc['bid'], 'salary' => $salary]);
if (count($rows) > 0)
return $this->json(['result' => 2]);
$name = $salary->getName();
$entityManager->remove($salary);
$log->insert('بانکداری', ' تنخواه‌گردان با نام ' . $name . ' حذف شد. ', $this->getUser(), $acc['bid']->getId());
return $this->json(['result' => 1]); return $this->json(['result' => 1]);
} }
} }

View file

@ -13,7 +13,7 @@ class SMS
private Settings $settings; private Settings $settings;
private registryMGR $registryMGR; private registryMGR $registryMGR;
private int $smsPrice = 2500; private int $smsPrice = 1250;
/** /**
* @param EntityManagerInterface $entityManager * @param EntityManagerInterface $entityManager