From 0ede84e4861b3742660edb4d4e3dd46d3ac90ce2 Mon Sep 17 00:00:00 2001 From: Babak Alizadeh Date: Mon, 13 Jan 2025 13:03:51 +0000 Subject: [PATCH] almost finish customizition of dashboard --- .../src/Controller/DashboardController.php | 71 +++++++++++++++++++ hesabixCore/src/Entity/DashboardSettings.php | 15 ++++ hesabixCore/src/Service/Explore.php | 40 +++++++++-- 3 files changed, 120 insertions(+), 6 deletions(-) create mode 100644 hesabixCore/src/Controller/DashboardController.php diff --git a/hesabixCore/src/Controller/DashboardController.php b/hesabixCore/src/Controller/DashboardController.php new file mode 100644 index 0000000..7c4dafa --- /dev/null +++ b/hesabixCore/src/Controller/DashboardController.php @@ -0,0 +1,71 @@ +hasRole('join'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $setting = $entityManagerInterface->getRepository(DashboardSettings::class)->findOneBy([ + 'submitter' => $this->getUser(), + 'bid' => $acc['bid'] + ]); + if (!$setting) { + $setting = new DashboardSettings(); + $setting->setSubmitter($this->getUser()); + $setting->setBid($acc['bid']); + $entityManagerInterface->persist($setting); + $entityManagerInterface->flush(); + } + + return $this->json($extractor->operationSuccess(Explore::ExploreDashboardSettings($setting))); + } + #[Route('/api/dashboard/settings/save', name: 'app_dashboard_save')] + public function app_dashboard_save(Request $request,Extractor $extractor, Access $access, EntityManagerInterface $entityManagerInterface): JsonResponse + { + $acc = $access->hasRole('join'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $setting = $entityManagerInterface->getRepository(DashboardSettings::class)->findOneBy([ + 'submitter' => $this->getUser(), + 'bid' => $acc['bid'] + ]); + if (!$setting) { + $setting = new DashboardSettings(); + $setting->setSubmitter($this->getUser()); + $setting->setBid($acc['bid']); + } + $params = $request->getPayload()->all(); + if(array_key_exists('banks',$params)) $setting->setBanks($params['banks']); + if(array_key_exists('buys',$params)) $setting->setBuys($params['buys']); + if(array_key_exists('sells',$params)) $setting->setSells($params['sells']); + if(array_key_exists('wallet',$params)) $setting->setWallet($params['wallet']); + if(array_key_exists('acc_docs',$params)) $setting->setAccDocs($params['acc_docs']); + if(array_key_exists('accounting_total',$params)) $setting->setAccountingTotal($params['accounting_total']); + if(array_key_exists('commodities',$params)) $setting->setCommodities($params['commodities']); + if(array_key_exists('persons',$params)) $setting->setPersons($params['persons']); + if(array_key_exists('notif',$params)) $setting->setNotif($params['notif']); + + $entityManagerInterface->persist($setting); + $entityManagerInterface->flush(); + + return $this->json($extractor->operationSuccess(Explore::ExploreDashboardSettings($setting))); + } +} diff --git a/hesabixCore/src/Entity/DashboardSettings.php b/hesabixCore/src/Entity/DashboardSettings.php index 653c2e9..4a65c3e 100644 --- a/hesabixCore/src/Entity/DashboardSettings.php +++ b/hesabixCore/src/Entity/DashboardSettings.php @@ -45,6 +45,9 @@ class DashboardSettings #[ORM\Column(nullable: true)] private ?bool $accountingTotal = null; + #[ORM\Column(nullable: true)] + private ?bool $notif = null; + public function getId(): ?int { return $this->id; @@ -169,4 +172,16 @@ class DashboardSettings return $this; } + + public function isNotif(): ?bool + { + return $this->notif; + } + + public function setNotif(?bool $notif): static + { + $this->notif = $notif; + + return $this; + } } diff --git a/hesabixCore/src/Service/Explore.php b/hesabixCore/src/Service/Explore.php index 018f911..224056f 100644 --- a/hesabixCore/src/Service/Explore.php +++ b/hesabixCore/src/Service/Explore.php @@ -3,6 +3,7 @@ namespace App\Service; use App\Entity\BankAccount; +use App\Entity\DashboardSettings; use App\Entity\Project; use App\Entity\Storeroom; use App\Entity\Support; @@ -72,7 +73,7 @@ class Explore $result['transferCost'] = 0; $result['person'] = $person; $result['pair_docs'] = []; - foreach($hesabdariDoc->getPairDoc() as $pair){ + foreach ($hesabdariDoc->getPairDoc() as $pair) { $result['pair_docs'][] = $pair->getCode(); } return $result; @@ -391,7 +392,7 @@ class Explore return [ 'id' => $user->getId(), 'name' => $user->getFullName(), - 'fullName'=>$user->getFullName() + 'fullName' => $user->getFullName() ]; } @@ -478,7 +479,7 @@ class Explore 'tel' => $item->getTel(), 'address' => $item->getAdr(), 'manager' => $item->getManager(), - 'active'=>$item->isActive() + 'active' => $item->isActive() ]; } @@ -542,20 +543,47 @@ class Explore return $res; } - public static function ExploreSupportTicket(Support $support,User | null $user):array{ + public static function ExploreSupportTicket(Support $support, User|null $user): array + { $jdate = new Jdate(); $res = []; $res['id'] = $support->getId(); $res['title'] = $support->getTitle(); $res['body'] = $support->getBody(); $res['state'] = $support->getState(); - $res['dateSubmit'] = $jdate->jdate('Y/n/d H:i',$support->getDateSubmit()); + $res['dateSubmit'] = $jdate->jdate('Y/n/d H:i', $support->getDateSubmit()); $res['submitter'] = self::ExploreUser($support->getSubmitter()); $res['main'] = $support->getMain(); $res['owner'] = true; - if($user->getId() != $support->getSubmitter()->getId()){ + if ($user->getId() != $support->getSubmitter()->getId()) { $res['owner'] = false; } return $res; } + + public static function ExploreDashboardSettings(DashboardSettings $item) + { + $result = [ + 'banks' => $item->isBanks(), + 'buys' => $item->isBuys(), + 'sells' => $item->isSells(), + 'wallet' => $item->isWallet(), + 'acc_docs'=> $item->isAccDocs(), + 'accounting_total'=>$item->isAccountingTotal(), + 'commodities'=>$item->isCommodities(), + 'persons'=>$item->isPersons(), + 'notif'=>$item->isNotif(), + ]; + if($result['banks'] === null) $result['banks'] = true; + if($result['buys'] === null) $result['buys'] = true; + if($result['sells'] === null) $result['sells'] = true; + if($result['wallet'] === null) $result['wallet'] = true; + if($result['acc_docs'] === null) $result['acc_docs'] = true; + if($result['accounting_total'] ===null) $result['accounting_total'] = true; + if($result['commodities'] === null) $result['commodities'] = true; + if($result['persons'] === null) $result['persons'] = true; + if($result['notif'] === null) $result['notif'] = true; + + return $result; + } }