diff --git a/hesabixCore/src/Controller/BankController.php b/hesabixCore/src/Controller/BankController.php index bb9accd..2e1bc8f 100644 --- a/hesabixCore/src/Controller/BankController.php +++ b/hesabixCore/src/Controller/BankController.php @@ -59,6 +59,58 @@ class BankController extends AbstractController return $this->json($provider->ArrayEntity2Array($datas, 0)); } + #[Route('/api/bank/search', name: 'app_bank_search')] + public function app_bank_search(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('banks'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + + $query = $entityManager->createQueryBuilder() + ->select('b') + ->from(BankAccount::class, 'b') + ->where('b.bid = :bid') + ->andWhere('b.money = :money') + ->setParameter('bid', $acc['bid']) + ->setParameter('money', $acc['money']); + + if (isset($params['search']) && !empty($params['search'])) { + $query->andWhere('b.name LIKE :search') + ->setParameter('search', '%' . $params['search'] . '%'); + } + + if (isset($params['page']) && isset($params['itemsPerPage'])) { + $query->setFirstResult(($params['page'] - 1) * $params['itemsPerPage']) + ->setMaxResults($params['itemsPerPage']); + } + + $datas = $query->getQuery()->getResult(); + + // محاسبه موجودی برای هر حساب + foreach ($datas as $data) { + $bs = 0; + $bd = 0; + $items = $entityManager->getRepository(HesabdariRow::class)->findBy([ + 'bank' => $data + ]); + foreach ($items as $item) { + $bs += $item->getBs(); + $bd += $item->getBd(); + } + $data->setBalance($bd - $bs); + } + + return $this->json([ + 'items' => $provider->ArrayEntity2Array($datas, 0), + 'total' => count($datas) + ]); + } + #[Route('/api/bank/info/{code}', name: 'app_bank_info')] public function app_bank_info($code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { @@ -147,6 +199,88 @@ class BankController extends AbstractController return $this->json(['result' => 1]); } + #[Route('/api/bank/balance/{code}', name: 'app_bank_balance')] + public function app_bank_balance($code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('banks'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $bank = $entityManager->getRepository(BankAccount::class)->findOneBy([ + 'bid' => $acc['bid'], + 'money' => $acc['money'], + 'code' => $code + ]); + + if (!$bank) + throw $this->createNotFoundException(); + + $bs = 0; + $bd = 0; + $items = $entityManager->getRepository(HesabdariRow::class)->findBy([ + 'bank' => $bank + ]); + + foreach ($items as $item) { + $bs += $item->getBs(); + $bd += $item->getBd(); + } + + return $this->json([ + 'balance' => $bd - $bs, + 'debit' => $bd, + 'credit' => $bs + ]); + } + + #[Route('/api/bank/transactions/{code}', name: 'app_bank_transactions')] + public function app_bank_transactions($code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('banks'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + + $bank = $entityManager->getRepository(BankAccount::class)->findOneBy([ + 'bid' => $acc['bid'], + 'money' => $acc['money'], + 'code' => $code + ]); + + if (!$bank) + throw $this->createNotFoundException(); + + $query = $entityManager->createQueryBuilder() + ->select('r') + ->from(HesabdariRow::class, 'r') + ->where('r.bank = :bank') + ->andWhere('r.bid = :bid') + ->setParameter('bank', $bank) + ->setParameter('bid', $acc['bid']); + + if (isset($params['startDate']) && isset($params['endDate'])) { + $query->andWhere('r.doc.date BETWEEN :startDate AND :endDate') + ->setParameter('startDate', $params['startDate']) + ->setParameter('endDate', $params['endDate']); + } + + if (isset($params['page']) && isset($params['itemsPerPage'])) { + $query->setFirstResult(($params['page'] - 1) * $params['itemsPerPage']) + ->setMaxResults($params['itemsPerPage']); + } + + $transactions = $query->getQuery()->getResult(); + + return $this->json([ + 'items' => $provider->ArrayEntity2Array($transactions, 0), + 'total' => count($transactions) + ]); + } + /** * @throws Exception */ diff --git a/hesabixCore/src/Controller/CashdeskController.php b/hesabixCore/src/Controller/CashdeskController.php index 3a65a25..10544e9 100644 --- a/hesabixCore/src/Controller/CashdeskController.php +++ b/hesabixCore/src/Controller/CashdeskController.php @@ -135,4 +135,137 @@ class CashdeskController extends AbstractController $log->insert('بانکداری', ' صندوق با نام ' . $name . ' حذف شد. ', $this->getUser(), $acc['bid']->getId()); return $this->json(['result' => 1]); } + + #[Route('/api/cashdesk/search', name: 'app_cashdesk_search')] + public function app_cashdesk_search(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('cashdesk'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + + $query = $entityManager->createQueryBuilder() + ->select('c') + ->from(Cashdesk::class, 'c') + ->where('c.bid = :bid') + ->andWhere('c.money = :money') + ->setParameter('bid', $acc['bid']) + ->setParameter('money', $acc['money']); + + if (isset($params['search']) && !empty($params['search'])) { + $query->andWhere('c.name LIKE :search') + ->setParameter('search', '%' . $params['search'] . '%'); + } + + if (isset($params['page']) && isset($params['itemsPerPage'])) { + $query->setFirstResult(($params['page'] - 1) * $params['itemsPerPage']) + ->setMaxResults($params['itemsPerPage']); + } + + $datas = $query->getQuery()->getResult(); + + foreach ($datas as $data) { + $bs = 0; + $bd = 0; + $items = $entityManager->getRepository(HesabdariRow::class)->findBy([ + 'cashdesk' => $data + ]); + foreach ($items as $item) { + $bs += $item->getBs(); + $bd += $item->getBd(); + } + $data->setBalance($bd - $bs); + } + + return $this->json([ + 'items' => $provider->ArrayEntity2Array($datas, 0), + 'total' => count($datas) + ]); + } + + #[Route('/api/cashdesk/balance/{code}', name: 'app_cashdesk_balance')] + public function app_cashdesk_balance($code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('cashdesk'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $cashdesk = $entityManager->getRepository(Cashdesk::class)->findOneBy([ + 'bid' => $acc['bid'], + 'money' => $acc['money'], + 'code' => $code + ]); + + if (!$cashdesk) + throw $this->createNotFoundException(); + + $bs = 0; + $bd = 0; + $items = $entityManager->getRepository(HesabdariRow::class)->findBy([ + 'cashdesk' => $cashdesk + ]); + + foreach ($items as $item) { + $bs += $item->getBs(); + $bd += $item->getBd(); + } + + return $this->json([ + 'balance' => $bd - $bs, + 'debit' => $bd, + 'credit' => $bs + ]); + } + + #[Route('/api/cashdesk/transactions/{code}', name: 'app_cashdesk_transactions')] + public function app_cashdesk_transactions($code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('cashdesk'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + + $cashdesk = $entityManager->getRepository(Cashdesk::class)->findOneBy([ + 'bid' => $acc['bid'], + 'money' => $acc['money'], + 'code' => $code + ]); + + if (!$cashdesk) + throw $this->createNotFoundException(); + + $query = $entityManager->createQueryBuilder() + ->select('r') + ->from(HesabdariRow::class, 'r') + ->where('r.cashdesk = :cashdesk') + ->andWhere('r.bid = :bid') + ->setParameter('cashdesk', $cashdesk) + ->setParameter('bid', $acc['bid']); + + if (isset($params['startDate']) && isset($params['endDate'])) { + $query->andWhere('r.doc.date BETWEEN :startDate AND :endDate') + ->setParameter('startDate', $params['startDate']) + ->setParameter('endDate', $params['endDate']); + } + + if (isset($params['page']) && isset($params['itemsPerPage'])) { + $query->setFirstResult(($params['page'] - 1) * $params['itemsPerPage']) + ->setMaxResults($params['itemsPerPage']); + } + + $transactions = $query->getQuery()->getResult(); + + return $this->json([ + 'items' => $provider->ArrayEntity2Array($transactions, 0), + 'total' => count($transactions) + ]); + } } diff --git a/hesabixCore/src/Controller/Componenets/BankController.php b/hesabixCore/src/Controller/Componenets/BankController.php new file mode 100644 index 0000000..be6bd8d --- /dev/null +++ b/hesabixCore/src/Controller/Componenets/BankController.php @@ -0,0 +1,33 @@ +getRepository(BankAccount::class)->find($id); + $acc = $access->hasRole('join'); + if (!$acc) { + return new JsonResponse(['message' => 'Access denied'], Response::HTTP_FORBIDDEN); + } + if (!$bank) { + return new JsonResponse(['message' => 'Bank not found'], Response::HTTP_NOT_FOUND); + } + if($bank->getBid() != $acc['bid']){ + return new JsonResponse(['message' => 'Access denied'], Response::HTTP_FORBIDDEN); + } + return new JsonResponse(Explore::ExploreBank($bank)); + } +} diff --git a/hesabixCore/src/Controller/Componenets/CashdeskController.php b/hesabixCore/src/Controller/Componenets/CashdeskController.php new file mode 100644 index 0000000..a09468a --- /dev/null +++ b/hesabixCore/src/Controller/Componenets/CashdeskController.php @@ -0,0 +1,33 @@ +getRepository(Cashdesk::class)->find($id); + $acc = $access->hasRole('join'); + if (!$acc) { + return new JsonResponse(['message' => 'Access denied'], Response::HTTP_FORBIDDEN); + } + if (!$cashdesk) { + return new JsonResponse(['message' => 'Cashdesk not found'], Response::HTTP_NOT_FOUND); + } + if($cashdesk->getBid() != $acc['bid']){ + return new JsonResponse(['message' => 'Access denied'], Response::HTTP_FORBIDDEN); + } + return new JsonResponse(Explore::ExploreCashdesk($cashdesk)); + } +} diff --git a/hesabixCore/src/Controller/DirectHesabdariDoc.php b/hesabixCore/src/Controller/DirectHesabdariDoc.php new file mode 100644 index 0000000..721190e --- /dev/null +++ b/hesabixCore/src/Controller/DirectHesabdariDoc.php @@ -0,0 +1,358 @@ +hasRole('accounting'); + if (!$acc) { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز'], 403); + } + + $prams = $request->getPayload()->all(); + + $hesabdariDoc = new HesabdariDoc(); + $hesabdariDoc->setType('calc'); + $hesabdariDoc->setBid($acc['bid']); + $hesabdariDoc->setSubmitter($this->getUser()); + $hesabdariDoc->setDes($prams['des']); + $hesabdariDoc->setYear($acc['year']); + $hesabdariDoc->setMoney($acc['money']); + $hesabdariDoc->setDate($prams['date']); + $hesabdariDoc->setCode($provider->getAccountingCode($acc['bid'], 'accounting')); + $hesabdariDoc->setDateSubmit(time()); + + //insert rows + if (isset($prams['rows'])) { + if (count($prams['rows']) < 2) { + return new JsonResponse(['success' => false, 'message' => 'حداقل باید دو سطر در سند وجود داشته باشد'], 400); + } + $totalBs = 0; + foreach ($prams['rows'] as $row) { + $hesabdariRow = new HesabdariRow(); + $hesabdariRow->setDoc($hesabdariDoc); + $hesabdariRow->setBs($row['bs']); + $hesabdariRow->setBd($row['bd']); + $hesabdariRow->setDes($row['des']); + $hesabdariRow->setYear($acc['year']); + $hesabdariRow->setRefData($row['detail']); + $hesabdariRow->setBid($acc['bid']); + $totalBs += floatval($row['bs']); + //get ref + $ref = $entityManager->getRepository(HesabdariTable::class)->find($row['ref']); + if ($ref) { + if ($ref->getBid() == $acc['bid'] || $ref->getBid() == null) { + $hesabdariRow->setRef($ref); + } else { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز به حساب'], 403); + } + } else { + return new JsonResponse(['success' => false, 'message' => 'حساب مورد نظر یافت نشد'], 404); + } + + if ($row['bankAccount']) { + $bankAccount = $entityManager->getRepository(BankAccount::class)->find($row['bankAccount']); + if ($bankAccount) { + if ($bankAccount->getBid() == $acc['bid']) { + $hesabdariRow->setBank($bankAccount); + } else { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز به حساب بانکی'], 403); + } + } else { + return new JsonResponse(['success' => false, 'message' => 'حساب بانکی مورد نظر یافت نشد'], 404); + } + } + if ($row['cashdesk']) { + $cashdesk = $entityManager->getRepository(Cashdesk::class)->find($row['cashdesk']); + if ($cashdesk) { + if ($cashdesk->getBid() == $acc['bid']) { + $hesabdariRow->setCashDesk($cashdesk); + } else { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز به صندوق'], 403); + } + } else { + return new JsonResponse(['success' => false, 'message' => 'صندوق مورد نظر یافت نشد'], 404); + } + } + + if ($row['salary']) { + $salary = $entityManager->getRepository(Salary::class)->find($row['salary']); + if ($salary) { + if ($salary->getBid() == $acc['bid']) { + $hesabdariRow->setSalary($salary); + } else { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز به حقوق'], 403); + } + } else { + return new JsonResponse(['success' => false, 'message' => 'حقوق مورد نظر یافت نشد'], 404); + } + } + + if ($row['person']) { + $person = $entityManager->getRepository(Person::class)->find($row['person']); + if ($person) { + if ($person->getBid() == $acc['bid']) { + $hesabdariRow->setPerson($person); + } else { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز به شخص'], 403); + } + } else { + return new JsonResponse(['success' => false, 'message' => 'شخص مورد نظر یافت نشد'], 404); + } + } + + if ($row['commodity'] && $row['commodityCount']) { + if (!is_numeric($row['commodityCount']) || $row['commodityCount'] <= 0) { + return new JsonResponse(['success' => false, 'message' => 'تعداد کالا باید عددی مثبت باشد'], 400); + } + $commodity = $entityManager->getRepository(Commodity::class)->find($row['commodity']); + if ($commodity) { + if ($commodity->getBid() == $acc['bid']) { + $hesabdariRow->setCommodity($commodity); + $hesabdariRow->setCommdityCount($row['commodityCount']); + } else { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز به کالا'], 403); + } + } else { + return new JsonResponse(['success' => false, 'message' => 'کالای مورد نظر یافت نشد'], 404); + } + } + $entityManager->persist($hesabdariRow); + } + $hesabdariDoc->setAmount($totalBs); + } + $entityManager->persist($hesabdariDoc); + $entityManager->flush(); + $log->insert('حسابداری', 'ایجاد سند حسابداری شماره ' . $hesabdariDoc->getCode(), $this->getUser(), $acc['bid'], $hesabdariDoc); + return new JsonResponse(['success' => true, 'message' => 'سند با موفقیت ثبت شد', 'data' => ['id' => $hesabdariDoc->getId()]], 200); + } + + #[Route('/api/hesabdari/direct/doc/update/{id}', name: 'update_hesabdari_doc_update')] + public function update(Log $log, Access $access, Request $request, int $id, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('accounting'); + if (!$acc) { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز'], 403); + } + + $hesabdariDoc = $entityManager->getRepository(HesabdariDoc::class)->find($id); + if (!$hesabdariDoc) { + return new JsonResponse(['success' => false, 'message' => 'سند مورد نظر یافت نشد'], 404); + } + + if ($hesabdariDoc->getBid() !== $acc['bid']) { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز به سند'], 403); + } + + $prams = $request->getPayload()->all(); + + $hesabdariDoc->setDes($prams['des']); + $hesabdariDoc->setDate($prams['date']); + + // حذف ردیفهای قبلی + foreach ($hesabdariDoc->getHesabdariRows() as $row) { + $entityManager->remove($row); + } + + // اضافه کردن ردیفهای جدید + if (isset($prams['rows'])) { + if (count($prams['rows']) < 2) { + return new JsonResponse(['success' => false, 'message' => 'حداقل باید دو سطر در سند وجود داشته باشد'], 400); + } + $totalBs = 0; + foreach ($prams['rows'] as $row) { + $hesabdariRow = new HesabdariRow(); + $hesabdariRow->setDoc($hesabdariDoc); + $hesabdariRow->setBs($row['bs']); + $hesabdariRow->setBd($row['bd']); + $hesabdariRow->setDes($row['des']); + $hesabdariRow->setYear($acc['year']); + $hesabdariRow->setRefData($row['detail']); + $hesabdariRow->setBid($acc['bid']); + $totalBs += floatval($row['bs']); + //get ref + $ref = $entityManager->getRepository(HesabdariTable::class)->find($row['ref']); + if ($ref) { + if ($ref->getBid() == $acc['bid'] || $ref->getBid() == null) { + $hesabdariRow->setRef($ref); + } else { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز به حساب'], 403); + } + } else { + return new JsonResponse(['success' => false, 'message' => 'حساب مورد نظر یافت نشد'], 404); + } + + if ($row['bankAccount']) { + $bankAccount = $entityManager->getRepository(BankAccount::class)->find($row['bankAccount']); + if ($bankAccount) { + if ($bankAccount->getBid() == $acc['bid']) { + $hesabdariRow->setBank($bankAccount); + } else { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز به حساب بانکی'], 403); + } + } else { + return new JsonResponse(['success' => false, 'message' => 'حساب بانکی مورد نظر یافت نشد'], 404); + } + } + + if ($row['cashdesk']) { + $cashdesk = $entityManager->getRepository(Cashdesk::class)->find($row['cashdesk']); + if ($cashdesk) { + if ($cashdesk->getBid() == $acc['bid']) { + $hesabdariRow->setCashDesk($cashdesk); + } else { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز به صندوق'], 403); + } + } else { + return new JsonResponse(['success' => false, 'message' => 'صندوق مورد نظر یافت نشد'], 404); + } + } + + if ($row['salary']) { + $salary = $entityManager->getRepository(Salary::class)->find($row['salary']); + if ($salary) { + if ($salary->getBid() == $acc['bid']) { + $hesabdariRow->setSalary($salary); + } else { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز به حقوق'], 403); + } + } else { + return new JsonResponse(['success' => false, 'message' => 'حقوق مورد نظر یافت نشد'], 404); + } + } + + if ($row['person']) { + $person = $entityManager->getRepository(Person::class)->find($row['person']); + if ($person) { + if ($person->getBid() == $acc['bid']) { + $hesabdariRow->setPerson($person); + } else { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز به شخص'], 403); + } + } else { + return new JsonResponse(['success' => false, 'message' => 'شخص مورد نظر یافت نشد'], 404); + } + } + + if ($row['commodity'] && $row['commodityCount']) { + if (!is_numeric($row['commodityCount']) || $row['commodityCount'] <= 0) { + return new JsonResponse(['success' => false, 'message' => 'تعداد کالا باید عددی مثبت باشد'], 400); + } + $commodity = $entityManager->getRepository(Commodity::class)->find($row['commodity']); + if ($commodity) { + if ($commodity->getBid() == $acc['bid']) { + $hesabdariRow->setCommodity($commodity); + $hesabdariRow->setCommdityCount($row['commodityCount']); + } else { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز به کالا'], 403); + } + } else { + return new JsonResponse(['success' => false, 'message' => 'کالای مورد نظر یافت نشد'], 404); + } + } + $entityManager->persist($hesabdariRow); + } + $hesabdariDoc->setAmount($totalBs); + } + + $entityManager->flush(); + $log->insert('حسابداری', 'ویرایش سند حسابداری شماره ' . $hesabdariDoc->getCode(), $this->getUser(), $acc['bid'], $hesabdariDoc); + return new JsonResponse(['success' => true, 'message' => 'سند با موفقیت ویرایش شد'], 200); + } + + #[Route('/api/hesabdari/direct/doc/delete/{id}', name: 'delete_hesabdari_doc_delete')] + public function delete(Log $log, Access $access, int $id, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('accounting'); + if (!$acc) { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز'], 403); + } + + $hesabdariDoc = $entityManager->getRepository(HesabdariDoc::class)->find($id); + if (!$hesabdariDoc) { + return new JsonResponse(['success' => false, 'message' => 'سند مورد نظر یافت نشد'], 404); + } + if ($hesabdariDoc->getType() !== 'calc') { + return new JsonResponse(['success' => false, 'message' => 'سند مورد نظر قابل حذف نیست'], 400); + } + if ($hesabdariDoc->getBid() !== $acc['bid']) { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز به سند'], 403); + } + + $entityManager->remove($hesabdariDoc); + $entityManager->flush(); + $log->insert('حسابداری', 'حذف سند حسابداری شماره ' . $hesabdariDoc->getCode(), $this->getUser(), $acc['bid'], $hesabdariDoc); + return new JsonResponse(['success' => true, 'message' => 'سند با موفقیت حذف شد'], 200); + } + + #[Route('/api/hesabdari/direct/doc/get/{id}', name: 'get_hesabdari_doc_get')] + public function get(Access $access, int $id, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('accounting'); + if (!$acc) { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز'], 403); + } + + $hesabdariDoc = $entityManager->getRepository(HesabdariDoc::class)->find($id); + if (!$hesabdariDoc) { + return new JsonResponse(['success' => false, 'message' => 'سند مورد نظر یافت نشد'], 404); + } + + if ($hesabdariDoc->getBid() !== $acc['bid']) { + return new JsonResponse(['success' => false, 'message' => 'دسترسی غیرمجاز به سند'], 403); + } + + $rows = []; + foreach ($hesabdariDoc->getHesabdariRows() as $row) { + $rowData = [ + 'id' => $row->getId(), + 'ref' => [ + 'id' => $row->getRef()->getId(), + 'name' => $row->getRef()->getName(), + 'tableType' => $row->getRef()->getType() + ], + 'bd' => $row->getBd(), + 'bs' => $row->getBs(), + 'des' => $row->getDes(), + 'detail' => $row->getRefData(), + 'bankAccount' => $row->getBank() ? $row->getBank()->getId() : null, + 'cashdesk' => $row->getCashDesk() ? $row->getCashDesk()->getId() : null, + 'salary' => $row->getSalary() ? $row->getSalary()->getId() : null, + 'commodity' => $row->getCommodity() ? $row->getCommodity()->getId() : null, + 'commodityCount' => $row->getCommdityCount(), + 'person' => $row->getPerson() ? $row->getPerson()->getId() : null + ]; + $rows[] = $rowData; + } + + $data = [ + 'id' => $hesabdariDoc->getId(), + 'date' => $hesabdariDoc->getDate(), + 'des' => $hesabdariDoc->getDes(), + 'code' => $hesabdariDoc->getCode(), + 'rows' => $rows + ]; + + return new JsonResponse(['success' => true, 'data' => $data], 200); + } +} diff --git a/hesabixCore/src/Controller/HesabdariController.php b/hesabixCore/src/Controller/HesabdariController.php index 811eae0..7605c78 100644 --- a/hesabixCore/src/Controller/HesabdariController.php +++ b/hesabixCore/src/Controller/HesabdariController.php @@ -1135,35 +1135,102 @@ class HesabdariController extends AbstractController } - #[Route('/api/hesabdari/tables/{id}/children', name: 'get_hesabdari_table_children', methods: ['GET'])] - public function getHesabdariTableChildren(int $id, Access $access, EntityManagerInterface $entityManager): JsonResponse + #[Route('/api/hesabdari/tables/tree', name: 'get_hesabdari_table_tree', methods: ['GET'])] + public function getHesabdariTableTree(Access $access, EntityManagerInterface $entityManager, Request $request): JsonResponse { $acc = $access->hasRole('accounting'); if (!$acc) { throw $this->createAccessDeniedException(); } - $node = $entityManager->getRepository(HesabdariTable::class)->find($id); - if (!$node) { - return $this->json(['Success' => false, 'message' => 'نود مورد نظر یافت نشد'], 404); + $depth = (int) $request->query->get('depth', 2); // عمق پیشفرض 2 + $rootId = (int) $request->query->get('rootId', 1); // گره ریشه پیشفرض + + $root = $entityManager->getRepository(HesabdariTable::class)->find($rootId); + if (!$root) { + return $this->json(['Success' => false, 'message' => 'نود ریشه یافت نشد'], 404); } - $children = $entityManager->getRepository(HesabdariTable::class)->findBy([ - 'upper' => $node, - 'bid' => [$acc['bid']->getId(), null] // حسابهای عمومی و خصوصی - ]); + $buildTree = function ($node, $depth, $currentDepth = 0) use ($entityManager, $acc, &$buildTree) { + if ($currentDepth >= $depth) { + return null; + } - $result = []; - foreach ($children as $child) { - $result[] = [ - 'id' => $child->getId(), - 'name' => $child->getName(), - 'code' => $child->getCode(), - 'type' => $child->getType(), - 'children' => $this->hasChild($entityManager, $child) ? [] : null - ]; + $children = $entityManager->getRepository(HesabdariTable::class)->findBy([ + 'upper' => $node, + 'bid' => [$acc['bid']->getId(), null], + ]); + + $result = []; + foreach ($children as $child) { + $childData = [ + 'id' => $child->getId(), + 'name' => $child->getName(), + 'code' => $child->getCode(), + 'type' => $child->getType(), + 'children' => $buildTree($child, $depth, $currentDepth + 1), + ]; + $result[] = $childData; + } + + return $result; + }; + + $tree = [ + 'id' => $root->getId(), + 'name' => $root->getName(), + 'code' => $root->getCode(), + 'type' => $root->getType(), + 'children' => $buildTree($root, $depth), + ]; + + return $this->json(['Success' => true, 'data' => $tree]); + } + + #[Route('/api/hesabdari/tables/all', name: 'get_all_hesabdari_tables', methods: ['GET'])] + public function getAllHesabdariTables(Access $access, EntityManagerInterface $entityManager, Request $request): JsonResponse + { + $acc = $access->hasRole('accounting'); + if (!$acc) { + throw $this->createAccessDeniedException(); } - return $this->json(['Success' => true, 'data' => $result]); + $rootId = (int) $request->query->get('rootId', 1); // گره ریشه پیشفرض + + $root = $entityManager->getRepository(HesabdariTable::class)->find($rootId); + if (!$root) { + return $this->json(['Success' => false, 'message' => 'نود ریشه یافت نشد'], 404); + } + + $buildTree = function ($node) use ($entityManager, $acc, &$buildTree) { + $children = $entityManager->getRepository(HesabdariTable::class)->findBy([ + 'upper' => $node, + 'bid' => [$acc['bid']->getId(), null], + ]); + + $result = []; + foreach ($children as $child) { + $childData = [ + 'id' => $child->getId(), + 'name' => $child->getName(), + 'code' => $child->getCode(), + 'type' => $child->getType(), + 'children' => $buildTree($child), + ]; + $result[] = $childData; + } + + return $result; + }; + + $tree = [ + 'id' => $root->getId(), + 'name' => $root->getName(), + 'code' => $root->getCode(), + 'type' => $root->getType(), + 'children' => $buildTree($root), + ]; + + return $this->json(['Success' => true, 'data' => $tree]); } } diff --git a/hesabixCore/src/Controller/SalaryController.php b/hesabixCore/src/Controller/SalaryController.php index abe667d..0a1a839 100644 --- a/hesabixCore/src/Controller/SalaryController.php +++ b/hesabixCore/src/Controller/SalaryController.php @@ -134,4 +134,137 @@ class SalaryController extends AbstractController $log->insert('بانکداری', ' تنخواهگردان با نام ' . $name . ' حذف شد. ', $this->getUser(), $acc['bid']->getId()); return $this->json(['result' => 1]); } + + #[Route('/api/salary/search', name: 'app_salary_search')] + public function app_salary_search(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('salary'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + + $query = $entityManager->createQueryBuilder() + ->select('s') + ->from(Salary::class, 's') + ->where('s.bid = :bid') + ->andWhere('s.money = :money') + ->setParameter('bid', $acc['bid']) + ->setParameter('money', $acc['money']); + + if (isset($params['search']) && !empty($params['search'])) { + $query->andWhere('s.name LIKE :search') + ->setParameter('search', '%' . $params['search'] . '%'); + } + + if (isset($params['page']) && isset($params['itemsPerPage'])) { + $query->setFirstResult(($params['page'] - 1) * $params['itemsPerPage']) + ->setMaxResults($params['itemsPerPage']); + } + + $datas = $query->getQuery()->getResult(); + + foreach ($datas as $data) { + $bs = 0; + $bd = 0; + $items = $entityManager->getRepository(HesabdariRow::class)->findBy([ + 'salary' => $data + ]); + foreach ($items as $item) { + $bs += $item->getBs(); + $bd += $item->getBd(); + } + $data->setBalance($bd - $bs); + } + + return $this->json([ + 'items' => $provider->ArrayEntity2Array($datas, 0), + 'total' => count($datas) + ]); + } + + #[Route('/api/salary/balance/{code}', name: 'app_salary_balance')] + public function app_salary_balance($code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('salary'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $salary = $entityManager->getRepository(Salary::class)->findOneBy([ + 'bid' => $acc['bid'], + 'money' => $acc['money'], + 'code' => $code + ]); + + if (!$salary) + throw $this->createNotFoundException(); + + $bs = 0; + $bd = 0; + $items = $entityManager->getRepository(HesabdariRow::class)->findBy([ + 'salary' => $salary + ]); + + foreach ($items as $item) { + $bs += $item->getBs(); + $bd += $item->getBd(); + } + + return $this->json([ + 'balance' => $bd - $bs, + 'debit' => $bd, + 'credit' => $bs + ]); + } + + #[Route('/api/salary/transactions/{code}', name: 'app_salary_transactions')] + public function app_salary_transactions($code, Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('salary'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + + $salary = $entityManager->getRepository(Salary::class)->findOneBy([ + 'bid' => $acc['bid'], + 'money' => $acc['money'], + 'code' => $code + ]); + + if (!$salary) + throw $this->createNotFoundException(); + + $query = $entityManager->createQueryBuilder() + ->select('r') + ->from(HesabdariRow::class, 'r') + ->where('r.salary = :salary') + ->andWhere('r.bid = :bid') + ->setParameter('salary', $salary) + ->setParameter('bid', $acc['bid']); + + if (isset($params['startDate']) && isset($params['endDate'])) { + $query->andWhere('r.doc.date BETWEEN :startDate AND :endDate') + ->setParameter('startDate', $params['startDate']) + ->setParameter('endDate', $params['endDate']); + } + + if (isset($params['page']) && isset($params['itemsPerPage'])) { + $query->setFirstResult(($params['page'] - 1) * $params['itemsPerPage']) + ->setMaxResults($params['itemsPerPage']); + } + + $transactions = $query->getQuery()->getResult(); + + return $this->json([ + 'items' => $provider->ArrayEntity2Array($transactions, 0), + 'total' => count($transactions) + ]); + } } diff --git a/hesabixCore/templates/pdf/printers/doc.html.twig b/hesabixCore/templates/pdf/printers/doc.html.twig index cdff9d8..660189c 100644 --- a/hesabixCore/templates/pdf/printers/doc.html.twig +++ b/hesabixCore/templates/pdf/printers/doc.html.twig @@ -1,18 +1,18 @@ {% extends 'pdf/base.html.twig' %} {% block body %} -
+ |
شماره سند: {{ doc.code }} |
- + |
نوع سند: {% if doc.type == 'cost' %} @@ -34,7 +34,7 @@ |
||||||||||||||||||||||||||||||||||||||||||||||||||
+ |
توضیحات:
{{ doc.des }}
@@ -88,9 +88,9 @@
{% elseif item.bank %}
{{item.bank.name}}
{% elseif item.cashdesk %}
- {{item.salary.name}}
- {% elseif item.salary %}
{{item.cashdesk.name}}
+ {% elseif item.salary %}
+ {{item.salary.name}}
{% else %}
{{item.ref.name}}
{% endif %}
diff --git a/webUI/package.json b/webUI/package.json
index 09be77a..bc95449 100644
--- a/webUI/package.json
+++ b/webUI/package.json
@@ -56,6 +56,7 @@
},
"devDependencies": {
"@types/file-saver": "^2.0.7",
+ "@types/lodash": "^4.17.16",
"@types/node": "^22.14.1",
"@vitejs/plugin-vue": "^5.2.3",
"@vitejs/plugin-vue-jsx": "^4.1.2",
diff --git a/webUI/src/components/forms/Haccountsearch.vue b/webUI/src/components/forms/Haccountsearch.vue
index 231848c..6bae414 100644
--- a/webUI/src/components/forms/Haccountsearch.vue
+++ b/webUI/src/components/forms/Haccountsearch.vue
@@ -1,303 +1,324 @@
- |