some progress in new face

This commit is contained in:
Hesabix 2023-11-12 08:52:01 -05:00
parent 6829d77730
commit e0448c8d99
11 changed files with 450 additions and 9 deletions

View file

@ -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);
}
}

View file

@ -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);

View file

@ -0,0 +1,30 @@
<?php
namespace App\Controller;
use App\Entity\Shareholder;
use App\Service\Access;
use App\Service\Log;
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;
class ShareHolderController extends AbstractController
{
#[Route('/api/shareholder/list', name: 'app_shareholder_list')]
public function app_shareholder_list(Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse
{
if(!$access->hasRole('shareholder'))
throw $this->createAccessDeniedException();
$datas = $entityManager->getRepository(Shareholder::class)->findBy([
'bid'=>$request->headers->get('activeBid')
]);
foreach($datas as $data){
}
return $this->json($datas);
}
}

View file

@ -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;
}
}

View file

@ -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<int, Shareholder>
*/
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;
}
}

View file

@ -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;
}
}

View file

@ -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<int, Shareholder>
*/
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;
}
}

View file

@ -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;
}
}

View file

@ -0,0 +1,67 @@
<?php
namespace App\Entity;
use App\Repository\ShareholderRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ShareholderRepository::class)]
class Shareholder
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'shareholders')]
#[ORM\JoinColumn(nullable: false)]
private ?Business $bid = null;
#[ORM\ManyToOne(inversedBy: 'shareholders')]
#[ORM\JoinColumn(nullable: false)]
private ?Person $person = null;
#[ORM\Column]
private ?int $percent = null;
public function getId(): ?int
{
return $this->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;
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace App\Repository;
use App\Entity\Shareholder;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Shareholder>
*
* @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()
// ;
// }
}

View file

@ -1,7 +1,7 @@
{% extends "base.html.twig" %}
{% block title %}نرم افزار حسابداری آنلاین ، متن باز و کاملا رایگان{% endblock %}
{% block body %}
<div class="px-4 py-3 text-center rounded-4 bg-light">
<div class="px-4 py-3 text-center rounded-4 bg-warning">
<div class="row">
<div class="col-sm-12 col-md-6">
<h1 class="fw-bold text-primary-darker">
@ -16,7 +16,7 @@
<i class="fa fa-door-open"></i>
ورود | عضویت رایگان
</a>
<button href="http://insider.hesabix.ir" disabled="disabled" class="btn btn-outline-warning btn-lg px-4 gap-3">
<button href="http://insider.hesabix.ir" disabled="disabled" class="btn btn-outline-dark btn-lg px-4 gap-3">
<i class="fa fa-door-open"></i>
پیش‌نمایش (فعلا غیرفعال است)
</button>
@ -27,11 +27,9 @@
</a>
{% endif %}
</div>
</div>
<div class="col-sm-12 col-md-6">
<img alt="پیش نمایش حسابیکس" class="img-fluid img-thumbnail" src="/img/cover.jpg" />
<img alt="پیش نمایش حسابیکس" class="img-fluid rounded-3" src="/img/cover.jpg" />
</div>
</div>
</div>