almost finish customizition of dashboard
This commit is contained in:
parent
6f30c0b11a
commit
0ede84e486
71
hesabixCore/src/Controller/DashboardController.php
Normal file
71
hesabixCore/src/Controller/DashboardController.php
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\DashboardSettings;
|
||||||
|
use App\Service\Access;
|
||||||
|
use App\Service\Explore;
|
||||||
|
use App\Service\Extractor;
|
||||||
|
use App\Service\JsonResp;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
|
||||||
|
class DashboardController extends AbstractController
|
||||||
|
{
|
||||||
|
#[Route('/api/dashboard/settings/load', name: 'app_dashboard_load')]
|
||||||
|
public function app_dashboard_load(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']);
|
||||||
|
$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)));
|
||||||
|
}
|
||||||
|
}
|
|
@ -45,6 +45,9 @@ class DashboardSettings
|
||||||
#[ORM\Column(nullable: true)]
|
#[ORM\Column(nullable: true)]
|
||||||
private ?bool $accountingTotal = null;
|
private ?bool $accountingTotal = null;
|
||||||
|
|
||||||
|
#[ORM\Column(nullable: true)]
|
||||||
|
private ?bool $notif = null;
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
return $this->id;
|
return $this->id;
|
||||||
|
@ -169,4 +172,16 @@ class DashboardSettings
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isNotif(): ?bool
|
||||||
|
{
|
||||||
|
return $this->notif;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setNotif(?bool $notif): static
|
||||||
|
{
|
||||||
|
$this->notif = $notif;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
use App\Entity\BankAccount;
|
use App\Entity\BankAccount;
|
||||||
|
use App\Entity\DashboardSettings;
|
||||||
use App\Entity\Project;
|
use App\Entity\Project;
|
||||||
use App\Entity\Storeroom;
|
use App\Entity\Storeroom;
|
||||||
use App\Entity\Support;
|
use App\Entity\Support;
|
||||||
|
@ -542,7 +543,8 @@ class Explore
|
||||||
return $res;
|
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();
|
$jdate = new Jdate();
|
||||||
$res = [];
|
$res = [];
|
||||||
$res['id'] = $support->getId();
|
$res['id'] = $support->getId();
|
||||||
|
@ -558,4 +560,30 @@ class Explore
|
||||||
}
|
}
|
||||||
return $res;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue