diff --git a/hesabixCore/src/Controller/ArchiveController.php b/hesabixCore/src/Controller/ArchiveController.php index 8ab2cf8..78b1db8 100644 --- a/hesabixCore/src/Controller/ArchiveController.php +++ b/hesabixCore/src/Controller/ArchiveController.php @@ -3,16 +3,21 @@ namespace App\Controller; use App\Entity\ArchiveFile; +use App\Entity\ArchiveOrders; +use App\Entity\Settings; use App\Service\Access; use App\Service\Jdate; use App\Service\Log; +use App\Service\Notification; use App\Service\Provider; +use App\Service\twigFunctions; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; 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; class ArchiveController extends AbstractController { @@ -22,9 +27,155 @@ class ArchiveController extends AbstractController $acc = $access->hasRole('archiveInfo'); if(!$acc) throw $this->createAccessDeniedException(); - return $this->json([ - 'size' => $acc['bid']->getArchiveSize() + $orders = $entityManager->getRepository(ArchiveOrders::class)->findBy([ + 'bid'=>$acc['bid'], + 'status'=>100 ]); + $totalSize = 0; + foreach ($orders as $order){ + if($order->getExpireDate()>= time()) + $totalSize += $order->getOrderSize(); + } + $usedSize = 0; + $files = $entityManager->getRepository(ArchiveFile::class)->findBy(['bid'=>$acc['bid']]); + foreach ($files as $file) + $usedSize += $file->getFileSize(); + return $this->json([ + 'size' => $totalSize * 1024, + 'remain'=>$usedSize + ]); + } + + #[Route('/api/archive/order/settings', name: 'app_archive_order_settings')] + public function app_archive_order_settings(twigFunctions $functions,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse + { + $acc = $access->hasRole('archiveInfo'); + if(!$acc) + throw $this->createAccessDeniedException(); + $settings = $functions->systemSettings(); + return $this->json([ + 'priceBase' => $settings->getStoragePrice() + ]); + } + + #[Route('/api/archive/order/submit', name: 'app_archive_order_submit')] + public function app_archive_order_submit(twigFunctions $functions,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse + { + $acc = $access->hasRole('archiveInfo'); + if(!$acc) + throw $this->createAccessDeniedException(); + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + + $order = new ArchiveOrders(); + $order->setBid($acc['bid']); + $order->setSubmitter($this->getUser()); + $order->setDateSubmit(time()); + $order->setGatePay('zarinpal'); + $order->setDes('خرید سرویس فضای ابری به مقدار ' . $params['space'] . ' گیگابایت به مدت ' . $params['month'] . ' ماه '); + + $settings = $functions->systemSettings(); + if(array_key_exists('space',$params) && array_key_exists('month',$params)){ + $order->setPrice($params['space'] * $params['month'] * $settings->getStoragePrice()); + $order->setOrderSize($params['space']); + $order->setMonth($params['month']); + } + else + throw $this->createAccessDeniedException(); + $data = array("merchant_id" => $settings->getZarinpalMerchant(), + "amount" => $order->getPrice(), + "callback_url" => $this->generateUrl('api_archive_buy_verify',[],UrlGeneratorInterface::ABSOLUTE_URL), + "description" => 'خرید سرویس فضای ابری', + ); + $jsonData = json_encode($data); + $ch = curl_init('https://api.zarinpal.com/pg/v4/payment/request.json'); + curl_setopt($ch, CURLOPT_USERAGENT, 'ZarinPal Rest Api v1'); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + 'Content-Length: ' . strlen($jsonData) + )); + + $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 { + if (empty($result['errors'])) { + if ($result['data']['code'] == 100) { + $order->setStatus(0); + $order->setVerifyCode($result['data']['authority']); + $entityManager->persist($order); + $entityManager->flush(); + $log->insert('سرویس فضای ابری','صدور فاکتور سرویس فضای ابری به مقدار ' . $params['space'] . ' گیگابایت به مدت ' . $params['month']. ' ماه ' ,$this->getUser(),$acc['bid']); + return $this->json([ + 'authority' => $result['data']["authority"] + ]); + } + } + } + throw $this->createAccessDeniedException(); + } + + #[Route('/api/archive/buy/verify', name: 'api_archive_buy_verify')] + public function api_archive_buy_verify(twigFunctions $functions,Notification $notification,Request $request,EntityManagerInterface $entityManager,Log $log): Response + { + $Authority = $request->get('Authority'); + $req = $entityManager->getRepository(ArchiveOrders::class)->findOneBy(['verifyCode'=>$Authority]); + //get system settings + $settings = $functions->systemSettings(); + $data = array("merchant_id" => $settings->getZarinpalMerchant(), "authority" => $Authority, "amount" => $req->getPrice()); + $jsonData = json_encode($data); + $ch = curl_init('https://api.zarinpal.com/pg/v4/payment/verify.json'); + curl_setopt($ch, CURLOPT_USERAGENT, 'ZarinPal Rest Api v4'); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'Content-Type: application/json', + 'Content-Length: ' . strlen($jsonData) + )); + + $result = curl_exec($ch); + $err = curl_error($ch); + curl_close($ch); + $result = json_decode($result, true); + + //----------------------------------- + + //----------------------------------- + if ($err) { + $log->insert('سرویس فضای ابری','پرداخت ناموفق سرویس فضای ابری' ,$this->getUser(),$req->getBid()); + return $this->render('buy/fail.html.twig', ['results'=>$result]); + } else { + if(array_key_exists('code',$result['data'])){ + if ($result['data']['code'] == 100) { + $req->setStatus($request->get('Status')); + $req->setRefID($result['data']['ref_id']); + $req->setCardPan($result['data']['card_pan']); + $req->setExpireDate(time() + ($req->getMonth() * 30 * 24 * 60 * 60)); + $entityManager->persist($req); + $entityManager->flush(); + $log->insert( + 'سرویس فضای ابری', + 'پرداخت موفق فاکتور سرویس فضای ابری', + $req->getSubmitter(), + $req->getBid() + ); + $notification->insert(' فاکتور فضای ابری پرداخت شد.','/acc/sms/panel',$req->getBid(),$req->getSubmitter()); + return $this->render('buy/success.html.twig',['req'=>$req]); + } + } + $notification->insert('پرداخت فاکتور فضای ابری ناموفق بود','/',$req->getBid(),$req->getSubmitter()); + $log->insert('سرویس پیامک','پرداخت ناموفق فاکتور فضای ابری' ,$this->getUser(),$req->getBid()); + return $this->render('buy/fail.html.twig', ['results'=>$result]); + } } #[Route('/api/archive/list/{cat}', name: 'app_archive_list')] @@ -56,4 +207,20 @@ class ArchiveController extends AbstractController return $this->json($resp); } + + #[Route('/api/archive/orders/list', name: 'app_archive_orders_list')] + public function app_archive_orders_list(Jdate $jdate, Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager,$code = 0): JsonResponse + { + $acc = $access->hasRole('archiveInfo'); + if (!$acc) + throw $this->createAccessDeniedException(); + $orders = $entityManager->getRepository(ArchiveOrders::class)->findBy([ + 'bid'=>$acc['bid'] + ],['id'=>'DESC']); + $resp = $provider->ArrayEntity2Array($orders,0); + foreach ($resp as &$item){ + $item['dateSubmit'] = $jdate->jdate('Y/n/d H:i',$item['dateSubmit']); + } + return $this->json($resp); + } } diff --git a/hesabixCore/src/Controller/BusinessController.php b/hesabixCore/src/Controller/BusinessController.php index 907d39c..d4d35b3 100644 --- a/hesabixCore/src/Controller/BusinessController.php +++ b/hesabixCore/src/Controller/BusinessController.php @@ -389,7 +389,8 @@ class BusinessController extends AbstractController 'archiveUpload'=>true, 'archiveMod'=>true, 'archiveDelete'=>true, - 'active'=> $perm->getUser()->isActive() + 'active'=> $perm->getUser()->isActive(), + 'shareholder'=>true, ]; } elseif($perm){ @@ -422,7 +423,8 @@ class BusinessController extends AbstractController 'archiveUpload'=>$perm->isArchiveUpload(), 'archiveMod'=>$perm->isArchiveMod(), 'archiveDelete'=>$perm->isArchiveDelete(), - 'active'=> $perm->getUser()->isActive() + 'active'=> $perm->getUser()->isActive(), + 'shareholder'=> $perm->isShareholder(), ]; } return $this->json($result); @@ -483,6 +485,7 @@ class BusinessController extends AbstractController $perm->setArchiveMod($params['archiveMod']); $perm->setArchiveDelete($params['archiveDelete']); $perm->setArchiveUpload($params['archiveUpload']); + $perm->setShareholder($params['shareholder']); $entityManager->persist($perm); $entityManager->flush(); $log->insert('تنظیمات پایه','ویرایش دسترسی‌های کاربر با پست الکترونیکی ' . $user->getEmail() ,$this->getUser(),$business); diff --git a/hesabixCore/src/Controller/ShareHolderController.php b/hesabixCore/src/Controller/ShareHolderController.php new file mode 100644 index 0000000..f93cfb2 --- /dev/null +++ b/hesabixCore/src/Controller/ShareHolderController.php @@ -0,0 +1,30 @@ +hasRole('shareholder')) + throw $this->createAccessDeniedException(); + $datas = $entityManager->getRepository(Shareholder::class)->findBy([ + 'bid'=>$request->headers->get('activeBid') + ]); + foreach($datas as $data){ + + } + return $this->json($datas); + } +} diff --git a/hesabixCore/src/Entity/ArchiveOrders.php b/hesabixCore/src/Entity/ArchiveOrders.php index 02e7f4c..b5fc331 100644 --- a/hesabixCore/src/Entity/ArchiveOrders.php +++ b/hesabixCore/src/Entity/ArchiveOrders.php @@ -48,6 +48,12 @@ class ArchiveOrders #[ORM\Column(length: 255, nullable: true)] private ?string $ExpireDate = null; + #[ORM\Column(length: 255, nullable: true)] + private ?string $des = null; + + #[ORM\Column(length: 255)] + private ?string $month = null; + public function getId(): ?int { return $this->id; @@ -184,4 +190,28 @@ class ArchiveOrders return $this; } + + public function getDes(): ?string + { + return $this->des; + } + + public function setDes(?string $des): static + { + $this->des = $des; + + return $this; + } + + public function getMonth(): ?string + { + return $this->month; + } + + public function setMonth(string $month): static + { + $this->month = $month; + + return $this; + } } diff --git a/hesabixCore/src/Entity/Business.php b/hesabixCore/src/Entity/Business.php index 18ddcae..4cfd723 100644 --- a/hesabixCore/src/Entity/Business.php +++ b/hesabixCore/src/Entity/Business.php @@ -196,6 +196,9 @@ class Business #[ORM\OneToMany(mappedBy: 'bid', targetEntity: ArchiveOrders::class, orphanRemoval: true)] private Collection $archiveOrders; + #[ORM\OneToMany(mappedBy: 'bid', targetEntity: Shareholder::class, orphanRemoval: true)] + private Collection $shareholders; + public function __construct() { $this->logs = new ArrayCollection(); @@ -219,6 +222,7 @@ class Business $this->storeroomItems = new ArrayCollection(); $this->archiveFiles = new ArrayCollection(); $this->archiveOrders = new ArrayCollection(); + $this->shareholders = new ArrayCollection(); } public function getId(): ?int @@ -1287,4 +1291,34 @@ class Business return $this; } + + /** + * @return Collection + */ + public function getShareholders(): Collection + { + return $this->shareholders; + } + + public function addShareholder(Shareholder $shareholder): static + { + if (!$this->shareholders->contains($shareholder)) { + $this->shareholders->add($shareholder); + $shareholder->setBid($this); + } + + return $this; + } + + public function removeShareholder(Shareholder $shareholder): static + { + if ($this->shareholders->removeElement($shareholder)) { + // set the owning side to null (unless already changed) + if ($shareholder->getBid() === $this) { + $shareholder->setBid(null); + } + } + + return $this; + } } diff --git a/hesabixCore/src/Entity/Permission.php b/hesabixCore/src/Entity/Permission.php index 5b2508d..8317115 100644 --- a/hesabixCore/src/Entity/Permission.php +++ b/hesabixCore/src/Entity/Permission.php @@ -96,6 +96,9 @@ class Permission #[ORM\Column(nullable: true)] private ?bool $archiveDelete = null; + #[ORM\Column(nullable: true)] + private ?bool $shareholder = null; + public function getId(): ?int { return $this->id; @@ -424,4 +427,16 @@ class Permission return $this; } + + public function isShareholder(): ?bool + { + return $this->shareholder; + } + + public function setShareholder(?bool $shareholder): static + { + $this->shareholder = $shareholder; + + return $this; + } } diff --git a/hesabixCore/src/Entity/Person.php b/hesabixCore/src/Entity/Person.php index b36e524..ed38591 100644 --- a/hesabixCore/src/Entity/Person.php +++ b/hesabixCore/src/Entity/Person.php @@ -110,12 +110,16 @@ class Person #[ORM\Column(length: 255, nullable: true)] private ?string $birthday = null; + #[ORM\OneToMany(mappedBy: 'person', targetEntity: Shareholder::class, orphanRemoval: true)] + private Collection $shareholders; + public function __construct() { $this->hesabdariRows = new ArrayCollection(); $this->plugNoghreOrders = new ArrayCollection(); $this->ordersFromCustomer = new ArrayCollection(); $this->storeroomTickets = new ArrayCollection(); + $this->shareholders = new ArrayCollection(); } public function getId(): ?int @@ -542,4 +546,34 @@ class Person return $this; } + + /** + * @return Collection + */ + public function getShareholders(): Collection + { + return $this->shareholders; + } + + public function addShareholder(Shareholder $shareholder): static + { + if (!$this->shareholders->contains($shareholder)) { + $this->shareholders->add($shareholder); + $shareholder->setPerson($this); + } + + return $this; + } + + public function removeShareholder(Shareholder $shareholder): static + { + if ($this->shareholders->removeElement($shareholder)) { + // set the owning side to null (unless already changed) + if ($shareholder->getPerson() === $this) { + $shareholder->setPerson(null); + } + } + + return $this; + } } diff --git a/hesabixCore/src/Entity/Settings.php b/hesabixCore/src/Entity/Settings.php index 56a9ef2..f64dc65 100644 --- a/hesabixCore/src/Entity/Settings.php +++ b/hesabixCore/src/Entity/Settings.php @@ -28,6 +28,9 @@ class Settings #[ORM\Column(length: 255, nullable: true)] private ?string $appSite = null; + #[ORM\Column(length: 255, nullable: true)] + private ?string $storagePrice = null; + public function getId(): ?int { return $this->id; @@ -92,4 +95,16 @@ class Settings return $this; } + + public function getStoragePrice(): ?string + { + return $this->storagePrice; + } + + public function setStoragePrice(?string $storagePrice): static + { + $this->storagePrice = $storagePrice; + + return $this; + } } diff --git a/hesabixCore/src/Entity/Shareholder.php b/hesabixCore/src/Entity/Shareholder.php new file mode 100644 index 0000000..2318970 --- /dev/null +++ b/hesabixCore/src/Entity/Shareholder.php @@ -0,0 +1,67 @@ +id; + } + + public function getBid(): ?Business + { + return $this->bid; + } + + public function setBid(?Business $bid): static + { + $this->bid = $bid; + + return $this; + } + + public function getPerson(): ?Person + { + return $this->person; + } + + public function setPerson(?Person $person): static + { + $this->person = $person; + + return $this; + } + + public function getPercent(): ?int + { + return $this->percent; + } + + public function setPercent(int $percent): static + { + $this->percent = $percent; + + return $this; + } +} diff --git a/hesabixCore/src/Repository/ShareholderRepository.php b/hesabixCore/src/Repository/ShareholderRepository.php new file mode 100644 index 0000000..6f51cbc --- /dev/null +++ b/hesabixCore/src/Repository/ShareholderRepository.php @@ -0,0 +1,48 @@ + + * + * @method Shareholder|null find($id, $lockMode = null, $lockVersion = null) + * @method Shareholder|null findOneBy(array $criteria, array $orderBy = null) + * @method Shareholder[] findAll() + * @method Shareholder[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class ShareholderRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Shareholder::class); + } + +// /** +// * @return Shareholder[] Returns an array of Shareholder objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('s') +// ->andWhere('s.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('s.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?Shareholder +// { +// return $this->createQueryBuilder('s') +// ->andWhere('s.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +} diff --git a/hesabixCore/templates/general/home.html.twig b/hesabixCore/templates/general/home.html.twig index eab083d..95989a6 100644 --- a/hesabixCore/templates/general/home.html.twig +++ b/hesabixCore/templates/general/home.html.twig @@ -1,7 +1,7 @@ {% extends "base.html.twig" %} {% block title %}نرم افزار حسابداری آنلاین ، متن باز و کاملا رایگان{% endblock %} {% block body %} -
+

@@ -16,7 +16,7 @@ ورود | عضویت رایگان - @@ -27,11 +27,9 @@ {% endif %}

- -
- پیش نمایش حسابیکس + پیش نمایش حسابیکس