From c2ea1148a6c9a5e4ef1c5ad2269ca3622d51e068 Mon Sep 17 00:00:00 2001 From: Babak Alizadeh Date: Tue, 21 Nov 2023 07:34:45 -0500 Subject: [PATCH] some progress in archive --- hesabixArchive/index.php | 1 + hesabixArchive/temp/index.php | 1 + hesabixCore/config/services.yaml | 2 + .../src/Controller/AdminController.php | 183 ++++++++++++++++++ .../src/Controller/ArchiveController.php | 59 +++++- hesabixCore/src/Controller/BlogController.php | 2 - .../src/Controller/Front/BlogController.php | 4 +- .../src/Controller/WalletController.php | 26 ++- hesabixCore/src/Entity/Settings.php | 15 ++ .../WalletTransactionRepository.php | 23 +-- hesabixCore/templates/base.html.twig | 29 ++- hesabixCore/templates/general/home.html.twig | 6 +- public_html/img/banner1.jpg | Bin 0 -> 65192 bytes public_html/img/banner2.webp | Bin 0 -> 38552 bytes public_html/img/logo-light.png | Bin 0 -> 9431 bytes 15 files changed, 300 insertions(+), 51 deletions(-) create mode 100644 hesabixArchive/index.php create mode 100644 hesabixArchive/temp/index.php create mode 100644 public_html/img/banner1.jpg create mode 100644 public_html/img/banner2.webp create mode 100644 public_html/img/logo-light.png diff --git a/hesabixArchive/index.php b/hesabixArchive/index.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/hesabixArchive/index.php @@ -0,0 +1 @@ +json($resp); } + #[Route('/api/admin/business/info/{id}', name: 'admin_business_info')] + public function admin_business_info(string $id,Jdate $jdate,#[CurrentUser] ?User $user,UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager,Request $request): Response + { + $bid = $entityManager->getRepository(Business::class)->find($id); + if(!$bid) + throw $this->createNotFoundException(); + $resp = []; + $resp['id'] = $bid->getId(); + $resp['name'] = $bid->getName(); + $resp['owner'] = $bid->getOwner()->getFullName(); + return $this->json($resp); + } + #[Route('/api/admin/business/list', name: 'admin_business_list')] + public function admin_business_list(Jdate $jdate,#[CurrentUser] ?User $user,UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager,Request $request): Response + { + $items = $entityManager->getRepository(Business::class)->findBy([],['id'=>'DESC']); + $resp = []; + foreach ($items as $item) { + $temp =[]; + $temp['id'] = $item->getId(); + $temp['name'] = $item->getName(); + $temp['owner'] = $item->getOwner()->getFullName(); + $temp['ownerMobile'] = $item->getOwner()->getMobile(); + $temp['dateRegister'] = $jdate->jdate('Y/n/d',$item->getDateSubmit()); + $temp['commodityCount'] = count($entityManager->getRepository(Commodity::class)->findBy(['bid'=>$item])); + $temp['personsCount'] = count($entityManager->getRepository(Person::class)->findBy(['bid'=>$item])); + $temp['hesabdariDocsCount'] = count($entityManager->getRepository(HesabdariDoc::class)->findBy(['bid'=>$item])); + $temp['StoreroomDocsCount'] = count($entityManager->getRepository(StoreroomTicket::class)->findBy(['bid'=>$item])); + + $resp[] = $temp; + } + return $this->json($resp); + } + + #[Route('/api/admin/settings/sms/info', name: 'admin_settings_sms_info')] + public function admin_settings_sms_info(Jdate $jdate,#[CurrentUser] ?User $user,UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager,Request $request): Response + { + $item = $entityManager->getRepository(Settings::class)->findAll()[0]; + $resp = []; + $url = 'https://console.melipayamak.com/api/receive/credit/' . $item->getMelipayamakToken(); + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, + array('Content-Type: application/json', + 'Content-Length: 0') + ); + $result = curl_exec($ch); + $err = curl_error($ch); + $result = json_decode($result, true, JSON_PRETTY_PRINT); + curl_close($ch); + if ($err) { + throw $this->createAccessDeniedException($err); + } else { + $resp['balanceCount'] = $result['amount']; + } + $resp['username'] = $item->getPayamakUsername(); + $resp['password'] = $item->getPayamakPassword(); + $resp['token'] = $item->getMelipayamakToken(); + return $this->json($resp); + } + #[Route('/api/admin/settings/sms/info/save', name: 'admin_settings_sms_info_save')] + public function admin_settings_sms_info_save(Jdate $jdate,#[CurrentUser] ?User $user,UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager,Request $request): Response + { + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + if(array_key_exists('username',$params) && array_key_exists('password',$params) && array_key_exists('token',$params)){ + $item = $entityManager->getRepository(Settings::class)->findAll()[0]; + $item->setPayamakPassword($params['password']); + $item->setPayamakUsername($params['username']); + $item->setMelipayamakToken($params['token']); + $entityManager->persist($item); + $entityManager->flush(); + return $this->json(['result' => 1]); + } + throw $this->createNotFoundException(); + } #[Route('/api/admin/reportchange/lists', name: 'app_admin_reportchange_list')] public function app_admin_reportchange_list(Jdate $jdate,Provider $provider,EntityManagerInterface $entityManager): JsonResponse { @@ -144,4 +234,97 @@ class AdminController extends AbstractController $entityManager->flush(); return $this->json(['result'=>1]); } + + #[Route('/api/admin/wallets/list', name: 'app_admin_wallets_list')] + public function app_admin_wallets_list(Jdate $jdate,Provider $provider,EntityManagerInterface $entityManager): JsonResponse + { + $bids = $entityManager->getRepository(Business::class)->findBy(['walletEnable'=>true]); + $resp = []; + foreach ($bids as $bid){ + $temp = []; + $walletPays = $entityManager->getRepository(WalletTransaction::class)->findBy(['bid'=>$bid,'type'=>'pay']); + $totalPays = 0; + foreach ($walletPays as $walletPay){ + $totalPays += $walletPay->getAmount(); + } + $temp['totalPays'] = $totalPays; + + $walletIncomes = $entityManager->getRepository(WalletTransaction::class)->findAllIncome($bid); + $totalIcome = 0; + foreach ($walletIncomes as $walletIncome){ + $totalIcome += $walletIncome->getAmount(); + } + $temp['totalIncome'] = $totalIcome; + + $temp['id'] = $bid->getId(); + $temp['bidName'] = $bid->getName(); + $temp['walletEnabled'] = $bid->isWalletEnable(); + if($bid->isWalletEnable()){ + $temp['bankAcName'] = $bid->getWalletMatchBank()->getName(); + $temp['bankAcShaba'] = $bid->getWalletMatchBank()->getShaba(); + $temp['bankAcOwner'] = $bid->getWalletMatchBank()->getOwner(); + $temp['bankAcCardNum'] = $bid->getWalletMatchBank()->getCardNum(); + } + + $resp[] = $temp; + } + return $this->json($resp); + } + + #[Route('/api/admin/wallets/transactions/list', name: 'app_admin_wallets_transactions_list')] + public function app_admin_wallets_transactions_list(Jdate $jdate,Provider $provider,EntityManagerInterface $entityManager): JsonResponse + { + $items = $entityManager->getRepository(WalletTransaction::class)->findAll(); + $resp = []; + foreach ($items as $item){ + $temp = []; + $temp['id'] = $item->getId(); + $temp['bidName'] = $item->getBid()->getName(); + $temp['walletEnabled'] = $item->getBid()->isWalletEnable(); + $temp['bankAcName'] = $item->getBid()->getWalletMatchBank()->getName(); + $temp['bankAcShaba'] = $item->getBid()->getWalletMatchBank()->getShaba(); + $temp['bankAcOwner'] = $item->getBid()->getWalletMatchBank()->getOwner(); + $temp['bankAcCardNum'] = $item->getBid()->getWalletMatchBank()->getCardNum(); + $temp['type'] = $item->getType(); + $temp['cardPan'] = $item->getCardPan(); + $temp['refID'] = $item->getRefID(); + $temp['shaba'] = $item->getShaba(); + $temp['dateSubmit'] = $jdate->jdate('Y/n/d H:i',$item->getDateSubmit()); + $temp['gatePay'] = $item->getGatePay(); + $resp[] = $temp; + } + return $this->json($resp); + } + + #[Route('/api/admin/wallets/transactions/insert', name: 'app_admin_wallets_transactions_insert')] + public function app_admin_wallets_transactions_insert(SMS $SMS,Jdate $jdate,Notification $notification,Request $request,EntityManagerInterface $entityManager): JsonResponse + { + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + if(array_key_exists('bank',$params) && array_key_exists('refID',$params) && array_key_exists('bid',$params) && array_key_exists('amount',$params) && array_key_exists('shaba',$params) && array_key_exists('card',$params)){ + $bid = $entityManager->getRepository(Business::class)->find($params['bid']['id']); + if(!$bid) + throw $this->createNotFoundException(); + $item = new WalletTransaction(); + $item->setBid($bid); + $item->setType('pay'); + $item->setShaba($params['shaba']); + $item->setAmount($params['amount']); + $item->setCardPan($params['card']); + $item->setDateSubmit(time()); + $item->setDes('واریز به حساب کسب و کار از طرف حسابیکس'); + $item->setRefID($params['refID']); + $item->setGatePay($params['bank']); + $item->setBank($bid->getWalletMatchBank()->getName()); + $entityManager->persist($item); + $entityManager->flush(); + $notification->insert('تسویه کیف پول انجام شد.','/acc/wallet/view',$bid,$bid->getOwner()); + $SMS->send([$bid->getName()],174225,$bid->getOwner()->getMobile()); + return $this->json(['result' => 1]); + + } + throw $this->createNotFoundException(); + } } diff --git a/hesabixCore/src/Controller/ArchiveController.php b/hesabixCore/src/Controller/ArchiveController.php index 78b1db8..086cf0d 100644 --- a/hesabixCore/src/Controller/ArchiveController.php +++ b/hesabixCore/src/Controller/ArchiveController.php @@ -13,20 +13,18 @@ use App\Service\Provider; use App\Service\twigFunctions; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +use Symfony\Component\Form\Extension\Core\Type\FileType; +use Symfony\Component\HttpFoundation\File\Exception\FileException; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; +use Symfony\Component\String\Slugger\SluggerInterface; class ArchiveController extends AbstractController { - #[Route('/api/archive/info', name: 'app_archive_info')] - public function app_archive_info(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse - { - $acc = $access->hasRole('archiveInfo'); - if(!$acc) - throw $this->createAccessDeniedException(); + private function getArchiveInfo(EntityManagerInterface $entityManager,array $acc){ $orders = $entityManager->getRepository(ArchiveOrders::class)->findBy([ 'bid'=>$acc['bid'], 'status'=>100 @@ -40,10 +38,19 @@ class ArchiveController extends AbstractController $files = $entityManager->getRepository(ArchiveFile::class)->findBy(['bid'=>$acc['bid']]); foreach ($files as $file) $usedSize += $file->getFileSize(); - return $this->json([ - 'size' => $totalSize * 1024, + return [ + 'size' => $totalSize * 1024, 'remain'=>$usedSize - ]); + ]; + } + #[Route('/api/archive/info', name: 'app_archive_info')] + public function app_archive_info(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse + { + $acc = $access->hasRole('archiveInfo'); + if(!$acc) + throw $this->createAccessDeniedException(); + $resp = $this->getArchiveInfo($entityManager,$acc); + return $this->json($resp); } #[Route('/api/archive/order/settings', name: 'app_archive_order_settings')] @@ -223,4 +230,38 @@ class ArchiveController extends AbstractController } return $this->json($resp); } + + #[Route('/api/archive/file/upload', name: 'app_archive_file_upload')] + public function app_archive_file_upload(Jdate $jdate, Provider $provider,SluggerInterface $slugger,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): Response + { + $acc = $access->hasRole('archiveUpload'); + if (!$acc) + throw $this->createAccessDeniedException(); + $info = $this->getArchiveInfo($entityManager,$acc); + if($info['remain'] > 0){ + $uploadedFile = $request->files->get('image'); + if ($uploadedFile) { + $originalFilename = pathinfo($uploadedFile->getClientOriginalName(), PATHINFO_FILENAME); + // this is needed to safely include the file name as part of the URL + $safeFilename = $slugger->slug($originalFilename); + $newFilename = $safeFilename.'-'.uniqid().'.'.$uploadedFile->guessExtension(); + + // Move the file to the directory where brochures are stored + + $uploadedFile->move( + $this->getParameter('archiveTempMediaDir'), + $newFilename + ); + try {} catch (FileException $e) { + // ... handle exception if something happens during file upload + } + + // updates the 'brochureFilename' property to store the PDF file name + // instead of its contents + //$product->setBrochureFilename($newFilename); + return new Response('ali.jpg'); + } + } + + } } diff --git a/hesabixCore/src/Controller/BlogController.php b/hesabixCore/src/Controller/BlogController.php index 8b21305..95aba2a 100644 --- a/hesabixCore/src/Controller/BlogController.php +++ b/hesabixCore/src/Controller/BlogController.php @@ -227,7 +227,6 @@ class BlogController extends AbstractController #[Route('/api/admin/blog/posts', name: 'app_admin_posts_get')] public function app_admin_posts_get(Jdate $jdate, Provider $provider,Request $request,SerializerInterface $serializer, EntityManagerInterface $entityManager): JsonResponse { - $items = array_reverse($entityManager->getRepository(BlogPost::class)->findAll()); $response = []; foreach ($items as $item){ @@ -239,7 +238,6 @@ class BlogController extends AbstractController $temp['url'] = $item->getUrl(); $temp['cat'] = $item->getCat()->getLabel(); $temp['dateSubmit'] = $jdate->jdate('Y/n/d H:i',$item->getDateSubmit()); - $temp['submitter'] = $item->getSubmitter()->getFullName(); $response[] = $temp; } return $this->json($response); diff --git a/hesabixCore/src/Controller/Front/BlogController.php b/hesabixCore/src/Controller/Front/BlogController.php index a088304..56b3f78 100644 --- a/hesabixCore/src/Controller/Front/BlogController.php +++ b/hesabixCore/src/Controller/Front/BlogController.php @@ -38,7 +38,9 @@ class BlogController extends AbstractController { $item = $entityManager->getRepository(BlogPost::class)->findOneBy(['url'=>$url]); if(!$item) throw $this->createNotFoundException(); - + $item->setViews($item->getViews() + 1); + $entityManager->persist($item); + $entityManager->flush(); $comment = new BlogComment(); $form = $this->createForm(CommentType::class,$comment); $form->handleRequest($request); diff --git a/hesabixCore/src/Controller/WalletController.php b/hesabixCore/src/Controller/WalletController.php index 4bce8c6..42ddd1c 100644 --- a/hesabixCore/src/Controller/WalletController.php +++ b/hesabixCore/src/Controller/WalletController.php @@ -20,14 +20,13 @@ class WalletController extends AbstractController if(!$acc) throw $this->createAccessDeniedException(); $items = $entityManager->getRepository(WalletTransaction::class)->findBy([ - 'bid' => $acc['bid'], - 'status'=>100 + 'bid' => $acc['bid'] ]); $pays = 0; $gets = 0; foreach ($items as $item){ if($item->getType() == 'pay') $pays += $item->getAmount(); - elseif ($item->getType() == 'get' || $item->getType() == 'sell') $gets += $item->getAmount(); + elseif (($item->getType() == 'get' || $item->getType() == 'sell') && $item->getStatus() == 100 ) $gets += $item->getAmount(); } return $this->json([ 'deposit' => $gets - $pays, @@ -35,15 +34,26 @@ class WalletController extends AbstractController 'turnover'=>$pays + $gets, ]); } - #[Route('/api/wallet/transactions', name: 'api_wallet_transactions')] - public function api_wallet_transactions(Jdate $jdate,EntityManagerInterface $entityManager,Access $access,Provider $provider): JsonResponse + #[Route('/api/wallet/transactions/{type}', name: 'api_wallet_transactions')] + public function api_wallet_transactions(Jdate $jdate,EntityManagerInterface $entityManager,Access $access,Provider $provider, string $type = 'all'): JsonResponse { $acc = $access->hasRole('wallet'); if(!$acc) throw $this->createAccessDeniedException(); - $items = $entityManager->getRepository(WalletTransaction::class)->findBy([ - 'bid' => $acc['bid'] - ],['id'=>'DESC']); + if($type == 'all'){ + $items = $entityManager->getRepository(WalletTransaction::class)->findBy([ + 'bid' => $acc['bid'] + ],['id'=>'DESC']); + } + elseif($type == 'pay'){ + $items = $entityManager->getRepository(WalletTransaction::class)->findBy([ + 'bid' => $acc['bid'], + 'type' => 'pay' + ],['id'=>'DESC']); + } + elseif($type == 'income'){ + $items = $entityManager->getRepository(WalletTransaction::class)->findAllIncome($acc['bid']); + } foreach ($items as $item){ $item->setDateSubmit($jdate->jdate('Y/n/d H:i',$item->getDateSubmit())); } diff --git a/hesabixCore/src/Entity/Settings.php b/hesabixCore/src/Entity/Settings.php index f64dc65..5e01804 100644 --- a/hesabixCore/src/Entity/Settings.php +++ b/hesabixCore/src/Entity/Settings.php @@ -31,6 +31,9 @@ class Settings #[ORM\Column(length: 255, nullable: true)] private ?string $storagePrice = null; + #[ORM\Column(length: 255, nullable: true)] + private ?string $melipayamakToken = null; + public function getId(): ?int { return $this->id; @@ -107,4 +110,16 @@ class Settings return $this; } + + public function getMelipayamakToken(): ?string + { + return $this->melipayamakToken; + } + + public function setMelipayamakToken(?string $melipayamakToken): static + { + $this->melipayamakToken = $melipayamakToken; + + return $this; + } } diff --git a/hesabixCore/src/Repository/WalletTransactionRepository.php b/hesabixCore/src/Repository/WalletTransactionRepository.php index 4df728e..34c9514 100644 --- a/hesabixCore/src/Repository/WalletTransactionRepository.php +++ b/hesabixCore/src/Repository/WalletTransactionRepository.php @@ -2,6 +2,7 @@ namespace App\Repository; +use App\Entity\Business; use App\Entity\WalletTransaction; use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; use Doctrine\Persistence\ManagerRegistry; @@ -24,17 +25,17 @@ class WalletTransactionRepository extends ServiceEntityRepository // /** // * @return WalletTransaction[] Returns an array of WalletTransaction objects // */ -// public function findByExampleField($value): array -// { -// return $this->createQueryBuilder('w') -// ->andWhere('w.exampleField = :val') -// ->setParameter('val', $value) -// ->orderBy('w.id', 'ASC') -// ->setMaxResults(10) -// ->getQuery() -// ->getResult() -// ; -// } + public function findAllIncome(Business $business): array + { + return $this->createQueryBuilder('w') + ->andWhere('w.bid = :val') + ->andWhere("w.type != 'pay'") + ->setParameter('val', $business) + ->orderBy('w.id', 'DESC') + ->getQuery() + ->getResult() + ; + } // public function findOneBySomeField($value): ?WalletTransaction // { diff --git a/hesabixCore/templates/base.html.twig b/hesabixCore/templates/base.html.twig index 17cd9f8..227a04f 100644 --- a/hesabixCore/templates/base.html.twig +++ b/hesabixCore/templates/base.html.twig @@ -33,33 +33,32 @@
-