From 87c081b38764f06aba6d6f33208fdabb8b1e4ce8 Mon Sep 17 00:00:00 2001 From: Babak Alizadeh Date: Sun, 29 Dec 2024 15:46:29 +0000 Subject: [PATCH] progress in openbalance and add shareholders --- hesabixCore/config/packages/security.yaml | 5 - .../src/Controller/AdminController.php | 25 + .../src/Controller/OpenbalanceController.php | 428 ++++++++++++++++++ hesabixCore/src/Service/SMS.php | 2 +- 4 files changed, 454 insertions(+), 6 deletions(-) create mode 100644 hesabixCore/src/Controller/OpenbalanceController.php diff --git a/hesabixCore/config/packages/security.yaml b/hesabixCore/config/packages/security.yaml index 0642f4f..57957f0 100644 --- a/hesabixCore/config/packages/security.yaml +++ b/hesabixCore/config/packages/security.yaml @@ -35,11 +35,6 @@ security: path: front_user_logout # where to redirect after logout target: general_home - form_login: - # "app_login" is the name of the route created previously - login_path: front_user_login - check_path: front_user_login - enable_csrf: true custom_authenticator: App\Security\BackAuthAuthenticator remember_me: secret: '%kernel.secret%' # required diff --git a/hesabixCore/src/Controller/AdminController.php b/hesabixCore/src/Controller/AdminController.php index c402317..2010c80 100644 --- a/hesabixCore/src/Controller/AdminController.php +++ b/hesabixCore/src/Controller/AdminController.php @@ -4,9 +4,11 @@ namespace App\Controller; use App\Entity\BankAccount; use App\Entity\Business; +use App\Entity\Cashdesk; use App\Entity\ChangeReport; use App\Entity\Commodity; use App\Entity\HesabdariDoc; +use App\Entity\Money; use App\Entity\Person; use App\Entity\Registry; use App\Entity\Settings; @@ -594,4 +596,27 @@ class AdminController extends AbstractController } echo str_replace("-", "/", "1403-02-06"); } + /** + * @throws Exception + */ + #[Route('/script2', name: 'script2')] + public function script2(EntityManagerInterface $entitymanager): JsonResponse + { + $banks = $entitymanager->getRepository(BankAccount::class)->findAll(); + foreach( $banks as $bank ){ + if($bank->getMoney() == null){ + $bank->setMoney($bank->getBid()->getMoney()); + $entitymanager->persist($bank); + } + } + + $items = $entitymanager->getRepository(Cashdesk::class)->findAll(); + foreach( $items as $item ){ + if($item->getMoney() == null){ + $item->setMoney($item->getBid()->getMoney()); + $entitymanager->persist($bank); + } + } + $entitymanager->flush(); + } } diff --git a/hesabixCore/src/Controller/OpenbalanceController.php b/hesabixCore/src/Controller/OpenbalanceController.php new file mode 100644 index 0000000..419f599 --- /dev/null +++ b/hesabixCore/src/Controller/OpenbalanceController.php @@ -0,0 +1,428 @@ +hasRole('accounting'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $res = []; + + //get open balance doc + $doc = $entityManagerInterface->getRepository(HesabdariDoc::class)->findOneBy([ + 'year' => $acc['year'], + 'bid' => $acc['bid'], + 'type' => 'open_balance', + 'money' => $acc['money'] + ]); + if (!$doc) + $doc = new HesabdariDoc(); + + //get banks + $banks = $entityManagerInterface->getRepository(BankAccount::class)->findBy([ + 'bid' => $acc['bid'], + 'money' => $acc['money'] + ]); + $banksDet = []; + foreach ($banks as $bank) { + $temp = []; + $temp['info'] = Explore::ExploreBank($bank); + foreach ($doc->getHesabdariRows() as $row) { + if ($row->getBank() == $bank) { + $temp['openbalance'] = $row->getBd(); + } + } + $banksDet[] = $temp; + } + $res['banks'] = $banksDet; + + //get cashdesks + $cashdesks = $entityManagerInterface->getRepository(Cashdesk::class)->findBy([ + 'bid' => $acc['bid'], + 'money' => $acc['money'] + ]); + $cashdesksDet = []; + foreach ($cashdesks as $cashdesk) { + $temp = []; + $temp['info'] = Explore::ExploreCashdesk($cashdesk); + foreach ($doc->getHesabdariRows() as $row) { + if ($row->getCashdesk() == $cashdesk) { + $temp['openbalance'] = $row->getBd(); + } + } + $cashdesksDet[] = $temp; + } + $res['cashdesks'] = $cashdesksDet; + + //get salarys + $salarys = $entityManagerInterface->getRepository(Salary::class)->findBy([ + 'bid' => $acc['bid'], + 'money' => $acc['money'] + ]); + $salaryDet = []; + foreach ($salarys as $salary) { + $temp = []; + $temp['info'] = Explore::ExploreSalary($salary); + foreach ($doc->getHesabdariRows() as $row) { + if ($row->getSalary() == $salary) { + $temp['openbalance'] = $row->getBd(); + } + } + $salaryDet[] = $temp; + } + $res['salarys'] = $salaryDet; + + //get shareholders + $shareholders = $entityManagerInterface->getRepository(Shareholder::class)->findBy([ + 'bid' => $acc['bid'], + ]); + $shareholderDet = []; + foreach ($shareholders as $shareholder) { + $temp = []; + $temp['info'] = Explore::ExplorePerson($shareholder->getPerson()); + foreach ($doc->getHesabdariRows() as $row) { + if ($row->getPerson() == $shareholder->getPerson() && $row->getRefData() == 'shareholder') { + $temp['openbalance'] = $row->getBs(); + } + } + $shareholderDet[] = $temp; + } + $res['shareholders'] = $shareholderDet; + + return $this->json($extractor->operationSuccess($res)); + } + + #[Route('/api/openbalance/save/banks', name: 'app_openbalance_save_banks')] + public function app_openbalance_save_banks(Provider $provider,Jdate $jdate, Request $request, Access $access, EntityManagerInterface $entityManagerInterface, Extractor $extractor): Response + { + $acc = $access->hasRole('accounting'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + + //get open balance doc + $doc = $entityManagerInterface->getRepository(HesabdariDoc::class)->findOneBy([ + 'year' => $acc['year'], + 'bid' => $acc['bid'], + 'type' => 'open_balance', + 'money' => $acc['money'] + ]); + if (!$doc) { + $doc = new HesabdariDoc(); + $doc->setBid($acc['bid']); + $doc->setAmount(0); + $doc->setDateSubmit(time()); + $doc->setMoney($acc['money']); + $doc->setSubmitter($this->getUser()); + $doc->setYear($acc['year']); + $doc->setDes('سند افتتاحیه'); + $doc->setDate($jdate->jdate('Y/n/d', time())); + $doc->setType('open_balance'); + $doc->setCode($provider->getAccountingCode($acc['bid'],'accounting')); + $entityManagerInterface->persist($doc); + } + + foreach ($params as $param) { + $bank = $entityManagerInterface->getRepository(BankAccount::class)->findOneBy([ + 'code' => $param['info']['code'], + 'bid' => $acc['bid'], + 'money' => $acc['money'] + ]); + $ExistBefore = false; + foreach ($doc->getHesabdariRows() as $row) { + if ($row->getBank() == $bank) { + if ($param['openbalance'] != 0) { + $ExistBefore = true; + $row->setBd($param['openbalance']); + $entityManagerInterface->persist($row); + } else { + $doc->removeHesabdariRow($row); + } + } + } + if ((!$ExistBefore) && $param['openbalance'] != 0) { + $row = new HesabdariRow(); + $row->setDoc($doc); + $row->setBank($bank); + $row->setBd($param['openbalance']); + $row->setBs(0); + $row->setBid($acc['bid']); + $row->setYear($acc['year']); + $row->setDes('موجودی اول دوره'); + $row->setRef($entityManagerInterface->getRepository(HesabdariTable::class)->findOneBy(['code' => 5])); + $entityManagerInterface->persist($row); + } + } + + //calculate amount of document + foreach ($doc->getHesabdariRows() as $row) { + $doc->setAmount($doc->getAmount() + $row->getBd()); + } + $entityManagerInterface->persist($doc); + + $entityManagerInterface->flush(); + return $this->json($extractor->operationSuccess()); + } + + #[Route('/api/openbalance/save/cashdesks', name: 'app_openbalance_save_cashdesk')] + public function app_openbalance_save_cashdesk(Provider $provider,Jdate $jdate, Request $request, Access $access, EntityManagerInterface $entityManagerInterface, Extractor $extractor): Response + { + $acc = $access->hasRole('accounting'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + + //get open balance doc + $doc = $entityManagerInterface->getRepository(HesabdariDoc::class)->findOneBy([ + 'year' => $acc['year'], + 'bid' => $acc['bid'], + 'type' => 'open_balance', + 'money' => $acc['money'] + ]); + if (!$doc) { + $doc = new HesabdariDoc(); + $doc->setBid($acc['bid']); + $doc->setAmount(0); + $doc->setDateSubmit(time()); + $doc->setMoney($acc['money']); + $doc->setSubmitter($this->getUser()); + $doc->setYear($acc['year']); + $doc->setDes('سند افتتاحیه'); + $doc->setDate($jdate->jdate('Y/n/d', time())); + $doc->setType('open_balance'); + $doc->setCode($provider->getAccountingCode($acc['bid'],'accounting')); + $entityManagerInterface->persist($doc); + } + + foreach ($params as $param) { + $cashdesk = $entityManagerInterface->getRepository(Cashdesk::class)->findOneBy([ + 'code' => $param['info']['code'], + 'bid' => $acc['bid'], + 'money' => $acc['money'] + ]); + $ExistBefore = false; + foreach ($doc->getHesabdariRows() as $row) { + if ($row->getCashdesk() == $cashdesk) { + if ($param['openbalance'] != 0) { + $ExistBefore = true; + $row->setBd($param['openbalance']); + $entityManagerInterface->persist($row); + } else { + $doc->removeHesabdariRow($row); + } + } + } + if ((!$ExistBefore) && $param['openbalance'] != 0) { + $row = new HesabdariRow(); + $row->setDoc($doc); + $row->setCashdesk($cashdesk); + $row->setBd($param['openbalance']); + $row->setBs(0); + $row->setBid($acc['bid']); + $row->setYear($acc['year']); + $row->setDes('موجودی اول دوره'); + $row->setRef($entityManagerInterface->getRepository(HesabdariTable::class)->findOneBy(['code' => 5])); + $entityManagerInterface->persist($row); + } + } + + //calculate amount of document + foreach ($doc->getHesabdariRows() as $row) { + $doc->setAmount($doc->getAmount() + $row->getBd()); + } + $entityManagerInterface->persist($doc); + + $entityManagerInterface->flush(); + return $this->json($extractor->operationSuccess()); + } + + #[Route('/api/openbalance/save/salarys', name: 'app_openbalance_save_salary')] + public function app_openbalance_save_salary(Provider $provider,Jdate $jdate, Request $request, Access $access, EntityManagerInterface $entityManagerInterface, Extractor $extractor): Response + { + $acc = $access->hasRole('accounting'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + + //get open balance doc + $doc = $entityManagerInterface->getRepository(HesabdariDoc::class)->findOneBy([ + 'year' => $acc['year'], + 'bid' => $acc['bid'], + 'type' => 'open_balance', + 'money' => $acc['money'] + ]); + if (!$doc) { + $doc = new HesabdariDoc(); + $doc->setBid($acc['bid']); + $doc->setAmount(0); + $doc->setDateSubmit(time()); + $doc->setMoney($acc['money']); + $doc->setSubmitter($this->getUser()); + $doc->setYear($acc['year']); + $doc->setDes('سند افتتاحیه'); + $doc->setDate($jdate->jdate('Y/n/d', time())); + $doc->setType('open_balance'); + $doc->setCode($provider->getAccountingCode($acc['bid'],'accounting')); + $entityManagerInterface->persist($doc); + } + + foreach ($params as $param) { + $salary = $entityManagerInterface->getRepository(Salary::class)->findOneBy([ + 'code' => $param['info']['code'], + 'bid' => $acc['bid'], + 'money' => $acc['money'] + ]); + $ExistBefore = false; + foreach ($doc->getHesabdariRows() as $row) { + if ($row->getSalary() == $salary) { + if ($param['openbalance'] != 0) { + $ExistBefore = true; + $row->setBd($param['openbalance']); + $entityManagerInterface->persist($row); + } else { + $doc->removeHesabdariRow($row); + } + } + } + if ((!$ExistBefore) && $param['openbalance'] != 0) { + $row = new HesabdariRow(); + $row->setDoc($doc); + $row->setSalary($salary); + $row->setBd($param['openbalance']); + $row->setBs(0); + $row->setBid($acc['bid']); + $row->setYear($acc['year']); + $row->setDes('موجودی اول دوره'); + $row->setRef($entityManagerInterface->getRepository(HesabdariTable::class)->findOneBy(['code' => 5])); + $entityManagerInterface->persist($row); + } + } + + //calculate amount of document + foreach ($doc->getHesabdariRows() as $row) { + $doc->setAmount($doc->getAmount() + $row->getBd()); + } + $entityManagerInterface->persist($doc); + + $entityManagerInterface->flush(); + return $this->json($extractor->operationSuccess()); + } + + #[Route('/api/openbalance/save/shareholders', name: 'app_openbalance_save_shareholder')] + public function app_openbalance_save_shareholder(Provider $provider,Jdate $jdate, Request $request, Access $access, EntityManagerInterface $entityManagerInterface, Extractor $extractor): Response + { + $acc = $access->hasRole('accounting'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + + //get open balance doc + $doc = $entityManagerInterface->getRepository(HesabdariDoc::class)->findOneBy([ + 'year' => $acc['year'], + 'bid' => $acc['bid'], + 'type' => 'open_balance', + 'money' => $acc['money'] + ]); + if (!$doc) { + $doc = new HesabdariDoc(); + $doc->setBid($acc['bid']); + $doc->setAmount(0); + $doc->setDateSubmit(time()); + $doc->setMoney($acc['money']); + $doc->setSubmitter($this->getUser()); + $doc->setYear($acc['year']); + $doc->setDes('سند افتتاحیه'); + $doc->setDate($jdate->jdate('Y/n/d', time())); + $doc->setType('open_balance'); + $doc->setCode($provider->getAccountingCode($acc['bid'],'accounting')); + $entityManagerInterface->persist($doc); + } + + foreach ($params as $param) { + $person = $entityManagerInterface->getRepository(Person::class)->findOneBy([ + 'code' => $param['info']['code'], + 'bid' => $acc['bid'], + ]); + if(!$person) return $this->json($extractor->operationFail()); + + $shareholder = $entityManagerInterface->getRepository(Shareholder::class)->findOneBy([ + 'person' => $person, + 'bid' => $acc['bid'], + ]); + $ExistBefore = false; + foreach ($doc->getHesabdariRows() as $row) { + if ($row->getPerson() == $shareholder->getPerson() && $row->getRefData() == 'shareholder') { + if ($param['openbalance'] != 0) { + $ExistBefore = true; + $row->setBs($param['openbalance']); + $entityManagerInterface->persist($row); + } else { + $doc->removeHesabdariRow($row); + } + } + } + if ((!$ExistBefore) && $param['openbalance'] != 0) { + $row = new HesabdariRow(); + $row->setDoc($doc); + $row->setPerson($shareholder->getPerson()); + $row->setBs($param['openbalance']); + $row->setBd(0); + $row->setRefData('shareholder'); + $row->setBid($acc['bid']); + $row->setYear($acc['year']); + $row->setDes('موجودی اول دوره'); + $row->setRef($entityManagerInterface->getRepository(HesabdariTable::class)->findOneBy(['code' => 5])); + $entityManagerInterface->persist($row); + } + } + + //calculate amount of document + foreach ($doc->getHesabdariRows() as $row) { + $doc->setAmount($doc->getAmount() + $row->getBd()); + } + $entityManagerInterface->persist($doc); + + $entityManagerInterface->flush(); + return $this->json($extractor->operationSuccess()); + } +} diff --git a/hesabixCore/src/Service/SMS.php b/hesabixCore/src/Service/SMS.php index ad9b930..c406171 100644 --- a/hesabixCore/src/Service/SMS.php +++ b/hesabixCore/src/Service/SMS.php @@ -66,7 +66,7 @@ class SMS $from = $this->registryMGR->get('sms', 'fromNum'); $input_data = []; foreach ($params as $param) { - $input_data['%' . strval(array_search($param, $params)) . '%'] = $param; + $input_data['%p' . strval(array_search($param, $params)) . '%'] = $param; } $url = "https://ippanel.com/patterns/pattern?username=" . $username . "&password=" . urlencode($password) . "&from=$from&to=" . json_encode($toArray) . "&input_data=" . urlencode(json_encode($input_data)) . "&pattern_code=$bodyID"; $handler = curl_init($url);