add year select to new business and some reports

This commit is contained in:
Hesabix 2024-04-22 15:25:12 +00:00
parent 267b28cf87
commit 5f7e68dfb1
5 changed files with 313 additions and 212 deletions

View file

@ -1,17 +0,0 @@
<?php
namespace App\Controller;
use App\Service\pdfMGR;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Annotation\Route;
class AdsBanController extends AbstractController
{
#[Route('/ads/ban', name: 'app_ads_ban')]
public function index(pdfMGR $pdfMGR): JsonResponse
{
$pdfMGR->streamTwig2PDF('test.html.twig');
}
}

View file

@ -33,11 +33,11 @@ use Symfony\Component\Security\Http\Attribute\CurrentUser;
class BusinessController extends AbstractController
{
#[Route('/api/business/list', name: 'api_bussiness_list')]
public function api_bussiness_list(#[CurrentUser] ?User $user,EntityManagerInterface $entityManager,Provider $provider): Response
public function api_bussiness_list(#[CurrentUser] ?User $user, EntityManagerInterface $entityManager, Provider $provider): Response
{
$buss = $entityManager->getRepository(Permission::class)->findBy(['user'=>$user]);
$buss = $entityManager->getRepository(Permission::class)->findBy(['user' => $user]);
$response = [];
foreach ($buss as $bus){
foreach ($buss as $bus) {
$temp = [];
$temp['id'] = $bus->getBid()->getId();
$temp['owner'] = $bus->getBid()->getOwner()->getFullName();
@ -52,9 +52,9 @@ class BusinessController extends AbstractController
* @throws ReflectionException
*/
#[Route('/api/business/get/info/{bid}', name: 'api_business_get_info')]
public function api_business_get_info($bid,#[CurrentUser] ?User $user,Provider $provider,EntityManagerInterface $entityManager): Response
public function api_business_get_info($bid, #[CurrentUser] ?User $user, Provider $provider, EntityManagerInterface $entityManager): Response
{
$bus = $entityManager->getRepository(Business::class)->findOneBy(['id'=>$bid]);
$bus = $entityManager->getRepository(Business::class)->findOneBy(['id' => $bid]);
$response = [];
$response['id'] = $bus->getId();
$response['name'] = $bus->getName();
@ -81,28 +81,28 @@ class BusinessController extends AbstractController
$response['shortlinks'] = $bus->isShortLinks();
$response['walletEnabled'] = $bus->isWalletEnable();
$response['walletMatchBank'] = null;
if($bus->isWalletEnable())
$response['walletMatchBank'] = $provider->Entity2Array($bus->getWalletMatchBank(),0);
if ($bus->isWalletEnable())
$response['walletMatchBank'] = $provider->Entity2Array($bus->getWalletMatchBank(), 0);
return $this->json($response);
}
#[Route('/api/business/list/count', name: 'api_bussiness_list_count')]
public function api_bussiness_list_count(#[CurrentUser] ?User $user,EntityManagerInterface $entityManager): Response
public function api_bussiness_list_count(#[CurrentUser] ?User $user, EntityManagerInterface $entityManager): Response
{
$buss = $entityManager->getRepository(Permission::class)->findBy(['user'=>$user]);
$response = ['count'=>count($buss)];
$buss = $entityManager->getRepository(Permission::class)->findBy(['user' => $user]);
$response = ['count' => count($buss)];
return $this->json($response);
}
#[Route('/api/business/insert', name: 'api_bussiness_insert')]
public function api_bussiness_insert(Jdate $jdate, Access $access,Log $log,Request $request,EntityManagerInterface $entityManager): Response
public function api_bussiness_insert(Jdate $jdate, Access $access, Log $log, Request $request, EntityManagerInterface $entityManager): Response
{
$params = [];
if ($content = $request->getContent()) {
$params = json_decode($content, true);
}
//check for that data is set
if(
if (
trim($params['name']) != '' &&
trim($params['legal_name']) != '' &&
trim($params['maliyatafzode']) != ''
@ -167,7 +167,7 @@ class BusinessController extends AbstractController
if ($params['email'])
$business->setEmail($params['email']);
if (array_key_exists('walletEnabled', $params)){
if (array_key_exists('walletEnabled', $params)) {
if ($params['walletEnabled']) {
if (array_key_exists('walletMatchBank', $params)) {
$bank = $entityManager->getRepository(BankAccount::class)->findOneBy([
@ -179,26 +179,24 @@ class BusinessController extends AbstractController
$business->setWalletMatchBank($bank);
}
}
}
else{
} else {
$business->setWalletEnable(false);
}
}
//get Money type
if($params['arzmain']){
$Arzmain = $entityManager->getRepository(Money::class)->findOneBy(['name'=>$params['arzmain']]);
if($Arzmain)
//get Money type
if ($params['arzmain']) {
$Arzmain = $entityManager->getRepository(Money::class)->findOneBy(['name' => $params['arzmain']]);
if ($Arzmain)
$business->setMoney($Arzmain);
else
return $this->json(['result'=>2]);
}
else
return $this->json(['result'=>2]);
if(! $business->getDateSubmit()) $business->setDateSubmit(time());
return $this->json(['result' => 2]);
} else
return $this->json(['result' => 2]);
if (!$business->getDateSubmit()) $business->setDateSubmit(time());
$entityManager->persist($business);
$entityManager->flush();
if($isNew){
if ($isNew) {
$perms = new Permission();
$perms->setBid($business);
$perms->setUser($this->getUser());
@ -229,50 +227,52 @@ class BusinessController extends AbstractController
$year = new Year();
$year->setBid($business);
$year->setHead(true);
$year->setStart(time());
$year->setEnd(time() + 31536000);
$year->setLabel('سال مالی منتهی به ' . $jdate->jdate('Y/n/d',time() + 31536000));
$startYearArray = explode('-', $params['year']['start']);
$year->setStart($jdate->jmktime(0, 0, 0, $startYearArray[1], $startYearArray[2], $startYearArray[0]));
$endYearArray = explode('-', $params['year']['end']);
$year->setEnd($jdate->jmktime(0, 0, 0, $endYearArray[1], $endYearArray[2], $endYearArray[0]));
$year->setLabel($params['year']['label']);
$entityManager->persist($year);
$entityManager->flush();
}
//add log to system
$log->insert('تنظیمات پایه','اطلاعات کسب و کار ایجاد/ویرایش شد.',$this->getUser(),$business);
$log->insert('تنظیمات پایه', 'اطلاعات کسب و کار ایجاد/ویرایش شد.', $this->getUser(), $business);
}
return $this->json(['result'=>1]);
return $this->json(['result' => 1]);
}
#[Route('/api/business/add/user', name: 'api_business_add_user')]
public function api_business_add_user(Access $access,Log $log,Request $request,EntityManagerInterface $entityManager): Response
public function api_business_add_user(Access $access, Log $log, Request $request, EntityManagerInterface $entityManager): Response
{
if(!$access->hasRole('permission'))
if (!$access->hasRole('permission'))
throw $this->createAccessDeniedException();
$params = [];
if ($content = $request->getContent()) {
$params = json_decode($content, true);
}
//check for that data is set
if(
if (
trim($params['bid']) != '' &&
trim($params['email']) != ''
){
) {
$business = $entityManager->getRepository(Business::class)->find($params['bid']);
if(is_null($business)){
return $this->json(['result'=>-1]);
if (is_null($business)) {
return $this->json(['result' => -1]);
}
//echo $params['email'];
$user = $entityManager->getRepository(User::class)->findOneBy([
'email' => $params['email']
'email' => $params['email']
]);
if(is_null($user)){
return $this->json(['result'=>0]);
if (is_null($user)) {
return $this->json(['result' => 0]);
}
$perm = $entityManager->getRepository(Permission::class)->findOneBy([
'user'=>$user,
'bid'=>$business
'user' => $user,
'bid' => $business
]);
if($perm){
if ($perm) {
//already added
return $this->json(['result'=>1]);
return $this->json(['result' => 1]);
}
$perm = new Permission();
$perm->setBid($business);
@ -281,74 +281,75 @@ class BusinessController extends AbstractController
$entityManager->persist($perm);
$entityManager->flush();
//add log to system
$log->insert('تنظیمات پایه','کاربر با پست الکترونیکی ' . $params['email'] .' به کسب و کار اضافه شد.',$this->getUser(),$business);
$log->insert('تنظیمات پایه', 'کاربر با پست الکترونیکی ' . $params['email'] . ' به کسب و کار اضافه شد.', $this->getUser(), $business);
return $this->json(
[
'result'=>2,
'data'=>[
'email'=>$user->getEmail(),
'name'=>$user->getFullName(),
'owner'=>false
'result' => 2,
'data' => [
'email' => $user->getEmail(),
'name' => $user->getFullName(),
'owner' => false
]
]);
]
);
}
return $this->json(['result'=>-1]);
return $this->json(['result' => -1]);
}
#[Route('/api/business/delete/user', name: 'api_business_delete_user')]
public function api_business_delete_user(Access $access,Log $log,Request $request,EntityManagerInterface $entityManager): Response
public function api_business_delete_user(Access $access, Log $log, Request $request, EntityManagerInterface $entityManager): Response
{
if(!$access->hasRole('permission'))
if (!$access->hasRole('permission'))
throw $this->createAccessDeniedException();
$params = [];
if ($content = $request->getContent()) {
$params = json_decode($content, true);
}
//check for that data is set
if(
if (
trim($params['bid']) != '' &&
trim($params['email']) != ''
){
) {
$business = $entityManager->getRepository(Business::class)->find($params['bid']);
if(is_null($business)){
return $this->json(['result'=>-1]);
if (is_null($business)) {
return $this->json(['result' => -1]);
}
//echo $params['email'];
$user = $entityManager->getRepository(User::class)->findOneBy([
'email' => $params['email']
]);
if(is_null($user)){
return $this->json(['result'=>-1]);
if (is_null($user)) {
return $this->json(['result' => -1]);
}
$perm = $entityManager->getRepository(Permission::class)->findOneBy([
'user'=>$user,
'bid'=>$business
'user' => $user,
'bid' => $business
]);
if($perm && ! $perm->isOwner()){
if ($perm && !$perm->isOwner()) {
$entityManager->remove($perm);
$entityManager->flush();
//add log to system
$log->insert('تنظیمات پایه','کاربر با پست الکترونیکی ' . $params['email'] .' از کسب و کار حذف شد.',$this->getUser(),$business);
return $this->json(['result'=>1]);
$log->insert('تنظیمات پایه', 'کاربر با پست الکترونیکی ' . $params['email'] . ' از کسب و کار حذف شد.', $this->getUser(), $business);
return $this->json(['result' => 1]);
}
}
return $this->json(['result'=>-1]);
return $this->json(['result' => -1]);
}
#[Route('/api/business/my/permission/state', name: 'api_business_my_permission_state')]
public function api_business_my_permission_state(Request $request,Access $access): Response
public function api_business_my_permission_state(Request $request, Access $access): Response
{
$reqdata = json_decode($request->getContent(), true);
if(!array_key_exists('permission',$reqdata)){
if (!array_key_exists('permission', $reqdata)) {
throw $this->createNotFoundException();
}
$acc = $access->hasRole($reqdata['permission']);
if($acc)
return $this->json(['state'=>true]);
return $this->json(['state'=>false]);
if ($acc)
return $this->json(['state' => true]);
return $this->json(['state' => false]);
}
#[Route('/api/business/get/user/permissions', name: 'api_business_get_user_permission')]
public function api_business_get_user_permission(Request $request,EntityManagerInterface $entityManager): Response
public function api_business_get_user_permission(Request $request, EntityManagerInterface $entityManager): Response
{
$params = [];
@ -356,131 +357,130 @@ class BusinessController extends AbstractController
$params = json_decode($content, true);
}
//check for that data is set
if(
if (
trim($params['bid']) != '' &&
trim($params['email']) != ''
){
) {
$business = $entityManager->getRepository(Business::class)->find($params['bid']);
if(is_null($business)){
return $this->json(['result'=>-1]);
if (is_null($business)) {
return $this->json(['result' => -1]);
}
$user = $entityManager->getRepository(User::class)->findOneBy([
'email' => $params['email']
]);
if(is_null($user)){
return $this->json(['result'=>-1]);
if (is_null($user)) {
return $this->json(['result' => -1]);
}
$perm = $entityManager->getRepository(Permission::class)->findOneBy([
'bid'=>$business,
'user'=>$user
'bid' => $business,
'user' => $user
]);
$result = [];
if($business->getOwner() == $user){
if ($business->getOwner() == $user) {
$result = [
'id'=>$perm->getUser()->getId(),
'user'=>$perm->getUser()->getFullName(),
'email'=>$perm->getUser()->getEmail(),
'settings'=>true,
'persons'=>true,
'commodity'=>true,
'cheque'=>true,
'getpay'=>true,
'store'=>true,
'bank'=>true,
'bankTransfer'=>true,
'cost'=>true,
'income'=>true,
'buy'=>true,
'sell'=>true,
'accounting'=>true,
'report'=>true,
'log'=>true,
'permission'=>true,
'salary'=>true,
'cashdesk'=>true,
'plugNoghreAdmin'=>true,
'plugNoghreSell'=>true,
'plugCCAdmin'=>true,
'wallet'=>true,
'owner'=> true,
'archiveUpload'=>true,
'archiveMod'=>true,
'archiveDelete'=>true,
'archiveView'=>true,
'active'=> $perm->getUser()->isActive(),
'shareholder'=>true,
'id' => $perm->getUser()->getId(),
'user' => $perm->getUser()->getFullName(),
'email' => $perm->getUser()->getEmail(),
'settings' => true,
'persons' => true,
'commodity' => true,
'cheque' => true,
'getpay' => true,
'store' => true,
'bank' => true,
'bankTransfer' => true,
'cost' => true,
'income' => true,
'buy' => true,
'sell' => true,
'accounting' => true,
'report' => true,
'log' => true,
'permission' => true,
'salary' => true,
'cashdesk' => true,
'plugNoghreAdmin' => true,
'plugNoghreSell' => true,
'plugCCAdmin' => true,
'wallet' => true,
'owner' => true,
'archiveUpload' => true,
'archiveMod' => true,
'archiveDelete' => true,
'archiveView' => true,
'active' => $perm->getUser()->isActive(),
'shareholder' => true,
];
}
elseif($perm){
} elseif ($perm) {
$result = [
'id'=>$perm->getUser()->getId(),
'user'=>$perm->getUser()->getFullName(),
'email'=>$perm->getUser()->getEmail(),
'settings'=>$perm->isSettings(),
'persons'=>$perm->isPerson(),
'commodity'=>$perm->isCommodity(),
'getpay'=>$perm->isGetpay(),
'bank'=>$perm->isBanks(),
'bankTransfer'=>$perm->isBankTransfer(),
'cost'=>$perm->isCost(),
'income'=>$perm->isIncome(),
'buy'=>$perm->isBuy(),
'cheque'=>$perm->isCheque(),
'sell'=>$perm->isSell(),
'accounting'=>$perm->isAccounting(),
'report'=>$perm->isReport(),
'log'=>$perm->isLog(),
'store'=>$perm->isStore(),
'permission'=>$perm->isPermission(),
'salary'=>$perm->isSalary(),
'cashdesk'=>$perm->isCashdesk(),
'plugNoghreAdmin'=>$perm->isPlugNoghreAdmin(),
'plugNoghreSell'=>$perm->isPlugNoghreSell(),
'plugCCAdmin'=>$perm->isPlugCCAdmin(),
'wallet'=>$perm->isWallet(),
'owner'=> false,
'archiveUpload'=>$perm->isArchiveUpload(),
'archiveMod'=>$perm->isArchiveMod(),
'archiveDelete'=>$perm->isArchiveDelete(),
'archiveView'=>$perm->isArchiveView(),
'active'=> $perm->getUser()->isActive(),
'shareholder'=> $perm->isShareholder(),
'id' => $perm->getUser()->getId(),
'user' => $perm->getUser()->getFullName(),
'email' => $perm->getUser()->getEmail(),
'settings' => $perm->isSettings(),
'persons' => $perm->isPerson(),
'commodity' => $perm->isCommodity(),
'getpay' => $perm->isGetpay(),
'bank' => $perm->isBanks(),
'bankTransfer' => $perm->isBankTransfer(),
'cost' => $perm->isCost(),
'income' => $perm->isIncome(),
'buy' => $perm->isBuy(),
'cheque' => $perm->isCheque(),
'sell' => $perm->isSell(),
'accounting' => $perm->isAccounting(),
'report' => $perm->isReport(),
'log' => $perm->isLog(),
'store' => $perm->isStore(),
'permission' => $perm->isPermission(),
'salary' => $perm->isSalary(),
'cashdesk' => $perm->isCashdesk(),
'plugNoghreAdmin' => $perm->isPlugNoghreAdmin(),
'plugNoghreSell' => $perm->isPlugNoghreSell(),
'plugCCAdmin' => $perm->isPlugCCAdmin(),
'wallet' => $perm->isWallet(),
'owner' => false,
'archiveUpload' => $perm->isArchiveUpload(),
'archiveMod' => $perm->isArchiveMod(),
'archiveDelete' => $perm->isArchiveDelete(),
'archiveView' => $perm->isArchiveView(),
'active' => $perm->getUser()->isActive(),
'shareholder' => $perm->isShareholder(),
];
}
return $this->json($result);
}
return $this->json(['result'=>-1]);
return $this->json(['result' => -1]);
}
#[Route('/api/business/save/user/permissions', name: 'api_business_save_user_permission')]
public function api_business_save_user_permission(Access $access,Log $log,Request $request,EntityManagerInterface $entityManager): Response
public function api_business_save_user_permission(Access $access, Log $log, Request $request, EntityManagerInterface $entityManager): Response
{
if(!$access->hasRole('permission'))
if (!$access->hasRole('permission'))
throw $this->createAccessDeniedException();
$params = [];
if ($content = $request->getContent()) {
$params = json_decode($content, true);
}
//check for that data is set
if(
if (
trim($params['bid']) != '' &&
trim($params['email']) != ''
){
) {
$business = $entityManager->getRepository(Business::class)->find($params['bid']);
if(is_null($business)){
return $this->json(['result'=>-1]);
if (is_null($business)) {
return $this->json(['result' => -1]);
}
$user = $entityManager->getRepository(User::class)->findOneBy([
'email' => $params['email']
]);
if(is_null($user)){
return $this->json(['result'=>-1]);
if (is_null($user)) {
return $this->json(['result' => -1]);
}
$perm = $entityManager->getRepository(Permission::class)->findOneBy([
'bid'=>$business,
'user'=>$user
'bid' => $business,
'user' => $user
]);
if($perm){
if ($perm) {
$perm->setSettings($params['settings']);
$perm->setPerson($params['persons']);
$perm->setGetpay($params['getpay']);
@ -510,74 +510,74 @@ class BusinessController extends AbstractController
$perm->setShareholder($params['shareholder']);
$entityManager->persist($perm);
$entityManager->flush();
$log->insert('تنظیمات پایه','ویرایش دسترسی‌های کاربر با پست الکترونیکی ' . $user->getEmail() ,$this->getUser(),$business);
$log->insert('تنظیمات پایه', 'ویرایش دسترسی‌های کاربر با پست الکترونیکی ' . $user->getEmail(), $this->getUser(), $business);
return $this->json(['result'=>1]);
return $this->json(['result' => 1]);
}
}
return $this->json(['result'=>-1]);
return $this->json(['result' => -1]);
}
#[Route('/api/business/stat', name: 'api_business_stat')]
public function api_business_stat(Request $request,#[CurrentUser] ?User $user,EntityManagerInterface $entityManager): Response
public function api_business_stat(Request $request, #[CurrentUser] ?User $user, EntityManagerInterface $entityManager): Response
{
$buss = $entityManager->getRepository(Business::class)->find(
$request->headers->get('activeBid')
);
if(!$buss)
if (!$buss)
throw $this->createNotFoundException();
$year = $entityManager->getRepository(Year::class)->find(
$request->headers->get('activeYear')
);
if(!$year)
if (!$year)
throw $this->createNotFoundException();
$persons = $entityManager->getRepository(Person::class)->findBy([
'bid'=>$buss
]);
'bid' => $buss
]);
$banks = $entityManager->getRepository(BankAccount::class)->findBy([
'bid'=>$buss
'bid' => $buss
]);
$docs = $entityManager->getRepository(HesabdariDoc::class)->findBy([
'bid'=>$buss,
'year'=>$year,
'bid' => $buss,
'year' => $year,
]);
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
'bid'=>$buss,
'year'=>$year
'bid' => $buss,
'year' => $year
]);
$bssum = 0;
foreach ($rows as $row)
$bssum += $row->getBs();
$buys = $entityManager->getRepository(HesabdariDoc::class)->findBy([
'bid'=>$buss,
'year'=>$year,
'type'=>'buy',
'bid' => $buss,
'year' => $year,
'type' => 'buy',
]);
$buysTotal = 0;
foreach($buys as $item)
foreach ($buys as $item)
$buysTotal += $item->getAmount();
$sells = $entityManager->getRepository(HesabdariDoc::class)->findBy([
'bid'=>$buss,
'year'=>$year,
'type'=>'sell',
'bid' => $buss,
'year' => $year,
'type' => 'sell',
]);
$sellsTotal = 0;
foreach($sells as $item)
foreach ($sells as $item)
$sellsTotal += $item->getAmount();
$response = [
'personCount'=>count($persons),
'bankCount'=>count($banks),
'docCount'=>count($docs),
'income'=> $bssum,
'commodity'=>count($entityManager->getRepository(Commodity::class)->findby([
'bid'=>$buss
'personCount' => count($persons),
'bankCount' => count($banks),
'docCount' => count($docs),
'income' => $bssum,
'commodity' => count($entityManager->getRepository(Commodity::class)->findby([
'bid' => $buss
])),
'buys_total'=>$buysTotal,
'sells_total'=>$sellsTotal,
'buys_total' => $buysTotal,
'sells_total' => $sellsTotal,
];
return $this->json($response);
}

View file

@ -23,6 +23,7 @@ use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
class PersonsController extends AbstractController
{
@ -208,8 +209,8 @@ class PersonsController extends AbstractController
return $this->json(['result' => 1]);
}
#[Route('/api/person/list', name: 'app_persons_list')]
public function app_persons_list(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse
#[Route('/api/person/list/limit', name: 'app_persons_list_limit')]
public function app_persons_list_limit(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse
{
if(!$access->hasRole('person'))
throw $this->createAccessDeniedException();
@ -228,7 +229,38 @@ class PersonsController extends AbstractController
'bid'=>$request->headers->get('activeBid')
]);
}
$response = $provider->ArrayEntity2Array($persons,0);
$response = [];
foreach ($persons as $key =>$person){
$response[] = [
'id' => $person->getId(),
'nikename'=>$person->getNikename(),
'code' =>$person->getCode(),
];
}
return $this->json($response);
}
#[Route('/api/person/list', name: 'app_persons_list')]
public function app_persons_list(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): Response
{
if(!$access->hasRole('person'))
throw $this->createAccessDeniedException();
$params = [];
if ($content = $request->getContent()) {
$params = json_decode($content, true);
}
if(array_key_exists('speedAccess',$params)){
$persons = $entityManager->getRepository(Person::class)->findBy([
'bid'=>$request->headers->get('activeBid'),
'speedAccess'=>true
]);
}
else{
$persons = $entityManager->getRepository(Person::class)->findBy([
'bid'=>$request->headers->get('activeBid')
]);
}
$response = Explore::ExplorePersons($persons,$entityManager->getRepository(PersonType::class)->findAll());
foreach ($persons as $key =>$person){
$rows = $entityManager->getRepository(HesabdariRow::class)->findBy([
'person'=>$person
@ -243,7 +275,7 @@ class PersonsController extends AbstractController
$response[$key]['bd'] = $bd;
$response[$key]['balance'] = $bs - $bd;
}
return $this->json($response);
return new Response(json_encode($response));
}
#[Route('/api/person/list/debtors/{amount}', name: 'app_persons_list_debtors')]

View file

@ -0,0 +1,86 @@
<?php
namespace App\Controller;
use App\Entity\HesabdariDoc;
use App\Entity\HesabdariRow;
use App\Entity\Person;
use App\Service\Access;
use App\Service\pdfMGR;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
class ReportController extends AbstractController
{
#[Route('/api/report/person/buysell', name: 'app_report_person_buysell')]
public function app_report_person_buysell(Access $access, Request $request, EntityManagerInterface $entityManagerInterface): JsonResponse
{
$acc = $access->hasRole('reports');
if (!$acc) {
throw $this->createAccessDeniedException();
}
$params = [];
if ($content = $request->getContent()) {
$params = json_decode($content, true);
}
$docs = $entityManagerInterface->getRepository(HesabdariDoc::class)->findBy([
'year' => $acc['year'],
'bid' => $acc['bid'],
'type' => $params['type'],
]);
$person = $entityManagerInterface->getRepository(Person::class)->findOneBy([
'bid' => $acc['bid']->getId(),
'code' => $params['person'],
]);
$result = [];
foreach ($docs as $doc) {
$rows = $doc->getHesabdariRows();
foreach ($rows as $row) {
if ($row->getPerson()) {
if ($person->getId() == $row->getPerson()->getId()) {
$result[] = $doc;
}
}
}
}
$docs = $result;
$result = [];
foreach ($docs as $doc) {
$rows = $doc->getHesabdariRows();
foreach ($rows as $row) {
if ($row->getCommodity()) {
$result[] = $row;
}
}
}
$response = [];
foreach ($result as $item) {
$temp = [
'id' => $item->getCommodity()->getId(),
'code' => $item->getCommodity()->getCode(),
'khadamat' => $item->getCommodity()->isKhadamat(),
'name' => $item->getCommodity()->getName(),
'unit' => $item->getCommodity()->getUnit()->getName(),
'count' => $item->getCommdityCount(),
];
if ($params['type'] == 'buy') {
$temp['priceAll'] = $item->getBd();
} elseif ($params['type'] == 'sell') {
$temp['priceAll'] = $item->getBs();
}
if ($temp['count'] != 0) {
$temp['priceOne'] = $temp['priceAll'] / $temp['count'];
$temp['priceAll'] = number_format($temp['priceAll']);
$temp['priceOne'] = number_format($temp['priceOne']);
$temp['count'] = number_format($temp['count']);
$response[] = $temp;
}
}
return $this->json($response);
}
}

View file

@ -181,7 +181,6 @@ class Explore{
'fax' => $person->getFax(),
'birthday' => $person->getBirthday(),
'speedAccess'=>$person->isSpeedAccess(),
];
$res['accounts'] = self::ExplorePersonCards($person);
$res['types'] = self::ExplorePersonTypes($typesAll);
@ -196,12 +195,13 @@ class Explore{
}
return null;
}
public static function ExplorePersons($items){
public static function ExplorePersons($items,$types){
$result = [];
foreach($items as $item)
$result[] = self::ExplorePerson($item);
$result[] = self::ExplorePerson($item,$types);
return $result;
}
public static function ExplorePersonCards(Person $person){
$res = [];
foreach($person->getPersonCards() as $item){