From 2fb24492074c3456e676ae9c013db4c8fd6ba973 Mon Sep 17 00:00:00 2001 From: Babak Alizadeh Date: Fri, 4 Apr 2025 11:26:49 +0000 Subject: [PATCH] progress in sustome controls --- hesabixCore/src/Controller/CostController.php | 143 +++- .../src/Controller/HesabdariController.php | 7 +- webUI/src/components/forms/Hpersonsearch.vue | 667 ++++++++++++++++++ .../src/components/forms/Htabletreeselect.vue | 8 + webUI/src/views/acc/costs/mod.vue | 23 +- 5 files changed, 826 insertions(+), 22 deletions(-) create mode 100644 webUI/src/components/forms/Hpersonsearch.vue diff --git a/hesabixCore/src/Controller/CostController.php b/hesabixCore/src/Controller/CostController.php index 219b515..716a027 100644 --- a/hesabixCore/src/Controller/CostController.php +++ b/hesabixCore/src/Controller/CostController.php @@ -12,6 +12,13 @@ use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\BinaryFileResponse; use App\Service\Provider; use App\Entity\HesabdariDoc; +use App\Entity\HesabdariRow; +use App\Entity\HesabdariTable; +use App\Entity\BankAccount; +use App\Entity\Cashdesk; +use App\Entity\Salary; +use App\Entity\Person; +use App\Service\Log; class CostController extends AbstractController { @@ -467,8 +474,6 @@ class CostController extends AbstractController $paymentCenter = $row->getCashdesk()->getName(); } elseif ($row->getSalary()) { $paymentCenter = $row->getSalary()->getName(); - } elseif ($row->getCommodity()) { - $paymentCenter = $row->getCommodity()->getName(); } elseif ($row->getPerson()) { $paymentCenter = $row->getPerson()->getNikename(); } @@ -492,4 +497,138 @@ class CostController extends AbstractController return new BinaryFileResponse($filePath); } + + #[Route('/api/cost/doc/insert', name: 'app_cost_doc_insert', methods: ['POST'])] + public function insertCostDoc( + Request $request, + Access $access, + EntityManagerInterface $entityManager, + Provider $provider, + Log $log, + Jdate $jdate + ): JsonResponse { + $acc = $access->hasRole('cost'); + if (!$acc) { + throw $this->createAccessDeniedException(); + } + + $params = json_decode($request->getContent(), true) ?? []; + + // بررسی پارامترهای ضروری + if (!isset($params['rows']) || count($params['rows']) < 2) { + return $this->json(['result' => 0, 'message' => 'حداقل دو ردیف برای سند هزینه الزامی است'], 400); + } + + if (!isset($params['date']) || !isset($params['des'])) { + return $this->json(['result' => 0, 'message' => 'تاریخ و شرح سند الزامی است'], 400); + } + + // تنظیم نوع سند به cost + $params['type'] = 'cost'; + + // بررسی وجود سند برای ویرایش + if (isset($params['update']) && $params['update'] != '') { + $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ + 'bid' => $acc['bid'], + 'year' => $acc['year'], + 'code' => $params['update'], + 'money' => $acc['money'] + ]); + if (!$doc) { + return $this->json(['result' => 0, 'message' => 'سند مورد نظر یافت نشد'], 404); + } + } + + // ایجاد سند جدید + $doc = new HesabdariDoc(); + $doc->setBid($acc['bid']); + $doc->setYear($acc['year']); + $doc->setDes($params['des']); + $doc->setDateSubmit(time()); + $doc->setType('cost'); + $doc->setDate($params['date']); + $doc->setSubmitter($this->getUser()); + $doc->setMoney($acc['money']); + $doc->setCode($provider->getAccountingCode($acc['bid'], 'accounting')); + + $entityManager->persist($doc); + $entityManager->flush(); + + // پردازش ردیف‌های سند + $amount = 0; + foreach ($params['rows'] as $row) { + $row['bs'] = str_replace(',', '', $row['bs']); + $row['bd'] = str_replace(',', '', $row['bd']); + + $hesabdariRow = new HesabdariRow(); + $hesabdariRow->setBid($acc['bid']); + $hesabdariRow->setYear($acc['year']); + $hesabdariRow->setDoc($doc); + $hesabdariRow->setBs($row['bs']); + $hesabdariRow->setBd($row['bd']); + + // تنظیم مرکز هزینه + $ref = $entityManager->getRepository(HesabdariTable::class)->findOneBy([ + 'code' => $row['table'] + ]); + $hesabdariRow->setRef($ref); + + // تنظیم مرکز پرداخت (بانک، صندوق، تنخواه، شخص) + if ($row['type'] == 'bank') { + $bank = $entityManager->getRepository(BankAccount::class)->findOneBy([ + 'id' => $row['id'], + 'bid' => $acc['bid'] + ]); + if (!$bank) { + return $this->json(['result' => 0, 'message' => 'حساب بانکی مورد نظر یافت نشد'], 404); + } + $hesabdariRow->setBank($bank); + } elseif ($row['type'] == 'cashdesk') { + $cashdesk = $entityManager->getRepository(Cashdesk::class)->find($row['id']); + if (!$cashdesk) { + return $this->json(['result' => 0, 'message' => 'صندوق مورد نظر یافت نشد'], 404); + } + $hesabdariRow->setCashdesk($cashdesk); + } elseif ($row['type'] == 'salary') { + $salary = $entityManager->getRepository(Salary::class)->find($row['id']); + if (!$salary) { + return $this->json(['result' => 0, 'message' => 'تنخواه مورد نظر یافت نشد'], 404); + } + $hesabdariRow->setSalary($salary); + } elseif ($row['type'] == 'person') { + $person = $entityManager->getRepository(Person::class)->findOneBy([ + 'id' => $row['id'], + 'bid' => $acc['bid'] + ]); + if (!$person) { + return $this->json(['result' => 0, 'message' => 'شخص مورد نظر یافت نشد'], 404); + } + $hesabdariRow->setPerson($person); + } + + if (isset($row['des'])) { + $hesabdariRow->setDes($row['des']); + } + + $entityManager->persist($hesabdariRow); + $amount += $row['bs']; + } + + $doc->setAmount($amount); + $entityManager->persist($doc); + $entityManager->flush(); + + $log->insert( + 'حسابداری', + 'سند هزینه شماره ' . $doc->getCode() . ' ثبت شد.', + $this->getUser(), + $acc['bid'], + $doc + ); + + return $this->json([ + 'result' => 1, + 'doc' => $provider->Entity2Array($doc, 0) + ]); + } } \ No newline at end of file diff --git a/hesabixCore/src/Controller/HesabdariController.php b/hesabixCore/src/Controller/HesabdariController.php index 91338cf..6528590 100644 --- a/hesabixCore/src/Controller/HesabdariController.php +++ b/hesabixCore/src/Controller/HesabdariController.php @@ -426,11 +426,12 @@ class HesabdariController extends AbstractController $entityManager->flush(); $hesabdariRow->setCheque($cheque); } elseif ($row['type'] == 'bank') { - $bank = $entityManager->getRepository(BankAccount::class)->find($row['id']); + $bank = $entityManager->getRepository(BankAccount::class)->findOneBy([ + 'id' => $row['id'], + 'bid' => $acc['bid'] + ]); if (!$bank) throw $this->createNotFoundException('bank not found'); - elseif ($bank->getBid()->getId() != $acc['bid']->getId()) - throw $this->createAccessDeniedException('bank is not in this business'); $hesabdariRow->setBank($bank); } elseif ($row['type'] == 'salary') { $salary = $entityManager->getRepository(Salary::class)->find($row['id']); diff --git a/webUI/src/components/forms/Hpersonsearch.vue b/webUI/src/components/forms/Hpersonsearch.vue new file mode 100644 index 0000000..4f349ef --- /dev/null +++ b/webUI/src/components/forms/Hpersonsearch.vue @@ -0,0 +1,667 @@ + + + + + diff --git a/webUI/src/components/forms/Htabletreeselect.vue b/webUI/src/components/forms/Htabletreeselect.vue index 1df3ca4..0e866e2 100644 --- a/webUI/src/components/forms/Htabletreeselect.vue +++ b/webUI/src/components/forms/Htabletreeselect.vue @@ -137,6 +137,14 @@ export default { try { const response = await axios.get('/api/accounting/table/childs/cost'); this.treeItems = response.data; + + if (this.modelValue) { + if (this.returnObject) { + this.selectedItem = this.modelValue; + } else { + this.selectedItem = this.findItemById(this.treeItems, this.modelValue); + } + } } catch (error) { console.error('خطا در دریافت داده‌ها:', error); this.$toast.error('خطا در بارگذاری داده‌ها'); diff --git a/webUI/src/views/acc/costs/mod.vue b/webUI/src/views/acc/costs/mod.vue index 9133677..b117038 100644 --- a/webUI/src/views/acc/costs/mod.vue +++ b/webUI/src/views/acc/costs/mod.vue @@ -295,15 +295,7 @@ - + { return { @@ -486,7 +480,7 @@ export default { }, addPerson() { this.persons.push({ - person: '', + id: '', amount: '', des: '' }) @@ -575,11 +569,6 @@ export default { axios.post('/api/salary/list').then((response) => { this.listSalarys = response.data; }); - - //get list of persons - axios.post('/api/person/list/search').then((response) => { - this.listPersons = response.data; - }); }, save() { let haszero = false; @@ -618,7 +607,7 @@ export default { } }) this.persons.forEach((item) => { - if (item.person == null || item.person == '') { + if (item.id == null || item.id == '') { sideOK = false; } }) @@ -697,7 +686,7 @@ export default { this.persons.forEach((item) => { if (item.des == '') item.des = 'هزینه' rows.push({ - id: item.person, + id: item.id, bs: parseInt(item.amount), bd: 0, des: item.des,