progress in explore accounts

This commit is contained in:
Hesabix 2025-01-30 09:49:41 +00:00
parent c65df9475e
commit 61dabcf451
5 changed files with 170 additions and 14 deletions

View file

@ -2,16 +2,110 @@
namespace App\Controller;
use App\Entity\BankAccount;
use App\Entity\Cashdesk;
use App\Entity\HesabdariRow;
use App\Entity\HesabdariTable;
use App\Service\Access;
use App\Service\Extractor;
use App\Service\Provider;
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\Attribute\Route;
final class ExploreAccountsController extends AbstractController
{
#[Route('/explore/accounts', name: 'app_explore_accounts')]
public function index(): JsonResponse
private $em;
private $provider;
function __construct(Provider $provider, EntityManagerInterface $entityManager)
{
$this->em = $entityManager;
$this->provider = $provider;
}
#[Route('/api/report/acc/explore_accounts_det', name: 'app_explore_accounts_det')]
public function app_explore_accounts_det(Access $access, Request $request, EntityManagerInterface $entityManagerInterface, Extractor $extractor): JsonResponse
{
$acc = $access->hasRole('report');
if (!$acc) {
throw $this->createAccessDeniedException();
}
$params = [];
if ($content = $request->getContent()) {
$params = json_decode($content, true);
}
if (!array_key_exists('node', $params))
throw $this->createNotFoundException();
// if($params['node'] == 'root'){
// $params['node'] = $entityManagerInterface
// ->getRepository(HesabdariTable::class)
// ->findOneBy(['upper'=>null])
// ->getId();
// }
if ($params['node'] == 'root') {
$params['node'] = 9;
}
$node = $entityManagerInterface->getRepository(HesabdariTable::class)->findNode($params['node'], $acc['bid']->getId());
if (!$node)
throw $this->createNotFoundException();
if ($node->getType() == 'bank') {
$rows = $this->getAllBanksRows($node, $acc);
} elseif ($node->getType() == 'cashdesk') {
} elseif ($node->getType() == 'salary') {
} elseif ($node->getType() == 'calc') {
echo 33;
} elseif ($node->getType() == 'person') {
} elseif ($node->getType() == 'commodity') {
} elseif ($node->getType() == 'cheque') {
}
return $this->json([]);
}
private function hasChild(HesabdariTable $table): bool
{
if ($this->em->getRepository(HesabdariTable::class)->findOneBy(['upper' => $table]))
return true;
return false;
}
private function getChilds(HesabdariTable $table): array
{
return $this->em->getRepository(HesabdariTable::class)->findBy(['upper' => $table]);
}
private function getAllBanksRows(HesabdariTable $table, array $acc): array
{
$items = $this->em->getRepository(BankAccount::class)->findBy([
'bid' => $acc['bid'],
'money' => $acc['money'],
]);
return $this->em->getRepository(HesabdariRow::class)->findByJoinMoney([
'bank' => $items,
'year' => $acc['year'],
'ref' => $table
], $acc['money']);
}
private function getAllCashdeskRows(HesabdariTable $table, array $acc): array
{
$items = $this->em->getRepository(Cashdesk::class)->findBy([
'bid' => $acc['bid'],
'money' => $acc['money'],
]);
return $this->em->getRepository(HesabdariRow::class)->findByJoinMoney([
'cashdesk' => $items,
'year' => $acc['year'],
'ref' => $table
], $acc['money']);
}
}

View file

@ -276,6 +276,12 @@ class Business
#[ORM\OneToMany(mappedBy: 'bid', targetEntity: DashboardSettings::class, orphanRemoval: true)]
private Collection $dashboardSettings;
/**
* @var Collection<int, HesabdariTable>
*/
#[ORM\OneToMany(mappedBy: 'bid', targetEntity: HesabdariTable::class)]
private Collection $hesabdariTables;
public function __construct()
{
$this->logs = new ArrayCollection();
@ -315,6 +321,7 @@ class Business
$this->preInvoiceDocs = new ArrayCollection();
$this->preInvoiceItems = new ArrayCollection();
$this->dashboardSettings = new ArrayCollection();
$this->hesabdariTables = new ArrayCollection();
}
public function getId(): ?int
@ -1929,4 +1936,34 @@ class Business
return $this;
}
/**
* @return Collection<int, HesabdariTable>
*/
public function getHesabdariTables(): Collection
{
return $this->hesabdariTables;
}
public function addHesabdariTable(HesabdariTable $hesabdariTable): static
{
if (!$this->hesabdariTables->contains($hesabdariTable)) {
$this->hesabdariTables->add($hesabdariTable);
$hesabdariTable->setBid($this);
}
return $this;
}
public function removeHesabdariTable(HesabdariTable $hesabdariTable): static
{
if ($this->hesabdariTables->removeElement($hesabdariTable)) {
// set the owning side to null (unless already changed)
if ($hesabdariTable->getBid() === $this) {
$hesabdariTable->setBid(null);
}
}
return $this;
}
}

View file

@ -33,6 +33,9 @@ class HesabdariTable
#[ORM\Column(length: 255, nullable: true)]
private ?string $entity = null;
#[ORM\ManyToOne(inversedBy: 'hesabdariTables')]
private ?Business $bid = null;
public function __construct()
{
$this->hesabdariRows = new ArrayCollection();
@ -132,4 +135,16 @@ class HesabdariTable
return $this;
}
public function getBid(): ?Business
{
return $this->bid;
}
public function setBid(?Business $bid): static
{
$this->bid = $bid;
return $this;
}
}

View file

@ -65,8 +65,18 @@ class HesabdariRowRepository extends ServiceEntityRepository
->where('d.money = :money')
->setParameter('money', $money);
foreach ($params as $key => $value) {
$query->andWhere('t.' . $key . '= :' . $key);
$query->setParameter($key, $value);
if (is_array($value)) {
$temp = [];
foreach ($value as $k => $v) {
$temp[] = $v->getId();
}
$query->andWhere('t.' . $key . ' IN (:' . $key . ')');
$query->setParameter($key, $temp);
} else {
$query->andWhere('t.' . $key . '= :' . $key);
$query->setParameter($key, $value);
}
}
return $query->getQuery()->getResult();
}

View file

@ -39,7 +39,7 @@ class HesabdariTableRepository extends ServiceEntityRepository
}
}
// /**
// /**
// * @return HesabdariTable[] Returns an array of HesabdariTable objects
// */
// public function findByExampleField($value): array
@ -54,13 +54,13 @@ class HesabdariTableRepository extends ServiceEntityRepository
// ;
// }
// public function findOneBySomeField($value): ?HesabdariTable
// {
// return $this->createQueryBuilder('h')
// ->andWhere('h.exampleField = :val')
// ->setParameter('val', $value)
// ->getQuery()
// ->getOneOrNullResult()
// ;
// }
public function findNode($value, $bid): ?HesabdariTable
{
return $this->createQueryBuilder('h')
->Where('h.id = :val AND (h.bid= :bid OR h.bid IS NULL)')
->setParameters(['val' => $value, 'bid' => $bid])
->getQuery()
->getOneOrNullResult()
;
}
}