diff --git a/hesabixCore/src/Controller/TransferController.php b/hesabixCore/src/Controller/TransferController.php index 10e6cb3..4941e75 100644 --- a/hesabixCore/src/Controller/TransferController.php +++ b/hesabixCore/src/Controller/TransferController.php @@ -4,6 +4,10 @@ namespace App\Controller; use App\Entity\HesabdariDoc; use App\Entity\HesabdariRow; +use App\Entity\BankAccount; +use App\Entity\Salary; +use App\Entity\Cashdesk; +use App\Entity\HesabdariTable; use App\Service\Access; use App\Service\Log; use App\Service\Provider; @@ -17,70 +21,184 @@ use Symfony\Component\Routing\Annotation\Route; class TransferController extends AbstractController { #[Route('/api/transfer/search', name: 'app_transfer_search')] - public function app_transfer_search(Provider $provider,Request $request,Access $access,Log $log,EntityManagerInterface $entityManager): JsonResponse + public function app_transfer_search(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse { $acc = $access->hasRole('bankTransfer'); - if(!$acc) + if (!$acc) throw $this->createAccessDeniedException(); - $items = $entityManager->getRepository(HesabdariDoc::class)->findBy([ - 'bid'=>$acc['bid'], - 'type'=>'transfer', - 'year'=>$acc['year'], - 'money'=> $acc['money'] - ], - ['dateSubmit'=>'DESC']); + $items = $entityManager->getRepository(HesabdariDoc::class)->findBy( + [ + 'bid' => $acc['bid'], + 'type' => 'transfer', + 'year' => $acc['year'], + 'money' => $acc['money'] + ], + ['dateSubmit' => 'DESC'] + ); $resp = []; - foreach ($items as $item){ + foreach ($items as $item) { $temp = []; - $temp['submitter']= $item->getSubmitter()->getFullName(); - $temp['code']= $item->getCode(); - $temp['date']= $item->getDate(); - $temp['des']= $item->getDes(); - $temp['amount']= $item->getAmount(); + $temp['submitter'] = $item->getSubmitter()->getFullName(); + $temp['code'] = $item->getCode(); + $temp['date'] = $item->getDate(); + $temp['des'] = $item->getDes(); + $temp['amount'] = $item->getAmount(); $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ - 'doc'=>$item + 'doc' => $item ]); $fromType = ''; $fromObject = ''; $toType = ''; $toObject = ''; - foreach ($rows as $row){ - if($row->getBs()!=0){ + foreach ($rows as $row) { + if ($row->getBs() != 0) { //it is from - if($row->getBank()){ + if ($row->getBank()) { $fromType = 'bank'; $fromObject = $row->getBank()->getName(); - } - elseif($row->getSalary()){ + } elseif ($row->getSalary()) { $fromType = 'salary'; $fromObject = $row->getSalary()->getName(); - } - elseif($row->getCashdesk()){ + } elseif ($row->getCashdesk()) { $fromType = 'cashDesk'; $fromObject = $row->getCashdesk()->getName(); } - } - else{ - if($row->getBank()){ + } else { + if ($row->getBank()) { $toType = 'bank'; $toObject = $row->getBank()->getName(); - } - elseif($row->getSalary()){ + } elseif ($row->getSalary()) { $toType = 'salary'; $toObject = $row->getSalary()->getName(); - } - elseif($row->getCashdesk()){ + } elseif ($row->getCashdesk()) { $toType = 'cashDesk'; $toObject = $row->getCashdesk()->getName(); } } } - $temp['fromType']= $fromType; - $temp['fromObject']= $fromObject; - $temp['toType']= $toType; - $temp['toObject']= $toObject; + $temp['fromType'] = $fromType; + $temp['fromObject'] = $fromObject; + $temp['toType'] = $toType; + $temp['toObject'] = $toObject; $resp[] = $temp; } return $this->json($resp); } + + #[Route('/api/transfer/insert', name: 'app_transfer_insert')] + public function app_transfer_insert(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager): JsonResponse + { + $acc = $access->hasRole('bankTransfer'); + if (!$acc) + throw $this->createAccessDeniedException(); + + $params = []; + if ($content = $request->getContent()) { + $params = json_decode($content, true); + } + + if (!array_key_exists('date', $params) || !array_key_exists('des', $params)) + throw $this->createNotFoundException('some params mistake'); + + if (array_key_exists('update', $params) && $params['update'] != '') { + $doc = $entityManager->getRepository(HesabdariDoc::class)->findOneBy([ + 'bid' => $acc['bid'], + 'year' => $acc['year'], + 'code' => $params['update'], + 'money' => $acc['money'] + ]); + if (!$doc) + throw $this->createNotFoundException('document not found.'); + $doc->setDes($params['des']); + $doc->setDate($params['date']); + $doc->setMoney($acc['money']); + + $entityManager->persist($doc); + $entityManager->flush(); + $rows = $entityManager->getRepository(HesabdariRow::class)->findBy([ + 'doc' => $doc + ]); + foreach ($rows as $row) + $entityManager->remove($row); + } else { + $doc = new HesabdariDoc(); + $doc->setBid($acc['bid']); + $doc->setYear($acc['year']); + $doc->setDes($params['des']); + $doc->setDateSubmit(time()); + $doc->setType('transfer'); + $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']); + $hesabdariRow->setDes($row['des']); + $hesabdariRow->setReferral($row['referral']); + if ($row['type'] == 'bank') { + $bank = $entityManager->getRepository(BankAccount::class)->findOneBy([ + 'id' => $row['id'], + 'bid' => $acc['bid'] + ]); + if (!$bank) + throw $this->createNotFoundException('bank not found'); + $hesabdariRow->setBank($bank); + $hesabdariRow->setRef($entityManager->getRepository(HesabdariTable::class)->findOneBy(['code' => '5'])); + + } elseif ($row['type'] == 'salary') { + $salary = $entityManager->getRepository(Salary::class)->findOneBy([ + 'id' => $row['id'], + 'bid' => $acc['bid'] + ]); + if (!$salary) + throw $this->createNotFoundException('salary not found'); + $hesabdariRow->setSalary($salary); + $hesabdariRow->setRef($entityManager->getRepository(HesabdariTable::class)->findOneBy(['code' => '122'])); + + } elseif ($row['type'] == 'cashdesk') { + $cashdesk = $entityManager->getRepository(Cashdesk::class)->findOneBy([ + 'id' => $row['id'], + 'bid' => $acc['bid'] + ]); + if (!$cashdesk) + throw $this->createNotFoundException('cashdesk not found'); + $hesabdariRow->setCashdesk($cashdesk); + $hesabdariRow->setRef($entityManager->getRepository(HesabdariTable::class)->findOneBy(['code' => '121'])); + + } + + $entityManager->persist($hesabdariRow); + $amount += $row['bs']; + } + + $doc->setAmount($amount); + $entityManager->persist($doc); + $entityManager->flush(); + + $log->insert( + 'حسابداری', + 'سند انتقال وجه شماره ' . $doc->getCode() . ' ثبت / ویرایش شد.', + $this->getUser(), + $request->headers->get('activeBid'), + $doc + ); + + return $this->json([ + 'result' => 1, + 'doc' => $provider->Entity2Array($doc, 0) + ]); + } } diff --git a/hesabixCore/templates/buy/fail.html.twig b/hesabixCore/templates/buy/fail.html.twig index cf32913..67b6497 100644 --- a/hesabixCore/templates/buy/fail.html.twig +++ b/hesabixCore/templates/buy/fail.html.twig @@ -10,7 +10,7 @@

متاسفانه پرداخت ناموفق بود!

- + بازگشت به پروفایل کاربری diff --git a/hesabixCore/templates/buy/success.html.twig b/hesabixCore/templates/buy/success.html.twig index 75e8730..a3bc89c 100644 --- a/hesabixCore/templates/buy/success.html.twig +++ b/hesabixCore/templates/buy/success.html.twig @@ -10,7 +10,7 @@

با تشکر از پرداخت شما. سفارش شما اعمال شد.

- + بازگشت به پروفایل کاربری diff --git a/webUI/src/components/forms/Hdatepicker.vue b/webUI/src/components/forms/Hdatepicker.vue index a281400..191763d 100644 --- a/webUI/src/components/forms/Hdatepicker.vue +++ b/webUI/src/components/forms/Hdatepicker.vue @@ -41,16 +41,15 @@ export default { }, data() { return { - displayDate: this.modelValue, // مقداردهی اولیه از prop - pickerActive: false, // کنترل باز شدن تقویم - minDatePersian: '', // تاریخ شروع سال مالی (شمسی برای پکیج) - maxDatePersian: '', // تاریخ پایان سال مالی (شمسی برای پکیج) - uniqueId: '', // شناسه یکتا برای هر نمونه - isInitialized: false, // فلگ برای کنترل مقداردهی اولیه + displayDate: '', // مقداردهی اولیه خالی + pickerActive: false, + minDatePersian: '', + maxDatePersian: '', + uniqueId: '', + isInitialized: false, }; }, created() { - // ایجاد شناسه یکتا برای هر نمونه از کامپوننت this.uniqueId = Math.random().toString(36).substring(2, 15); }, watch: { @@ -62,7 +61,7 @@ export default { modelValue: { immediate: true, handler(newVal) { - if (newVal && newVal !== this.displayDate) { + if (newVal) { this.displayDate = newVal; } } @@ -78,8 +77,8 @@ export default { this.minDatePersian = response.data.start; this.maxDatePersian = response.data.end; - // فقط اگر مقدار اولیه نداریم، از تاریخ جاری استفاده کنیم - if (!this.modelValue && !this.isInitialized) { + // فقط اگر مقدار اولیه نداریم و هنوز مقداردهی نشده، از تاریخ جاری استفاده کنیم + if (!this.modelValue && !this.displayDate && !this.isInitialized) { this.displayDate = response.data.now; this.$emit('update:modelValue', response.data.now); this.isInitialized = true; diff --git a/webUI/src/i18n/fa_lang.ts b/webUI/src/i18n/fa_lang.ts index ef4552c..7f2621b 100644 --- a/webUI/src/i18n/fa_lang.ts +++ b/webUI/src/i18n/fa_lang.ts @@ -268,7 +268,9 @@ const fa_lang = { count: "تعداد", }, dialog: { + download: 'دانلود', delete_group: 'حذف گروهی', + add_new_transfer: 'سند انتقال جدید', acc_price: 'مبلغ', des: 'شرح', warning: 'هشدار', diff --git a/webUI/src/views/acc/archive/order_new.vue b/webUI/src/views/acc/archive/order_new.vue index e5f868d..cd9fd93 100644 --- a/webUI/src/views/acc/archive/order_new.vue +++ b/webUI/src/views/acc/archive/order_new.vue @@ -1,57 +1,88 @@ diff --git a/webUI/src/views/acc/archive/orders_list.vue b/webUI/src/views/acc/archive/orders_list.vue index f473c88..936fefe 100644 --- a/webUI/src/views/acc/archive/orders_list.vue +++ b/webUI/src/views/acc/archive/orders_list.vue @@ -1,92 +1,81 @@ \ No newline at end of file diff --git a/webUI/src/views/acc/archive/view_files.vue b/webUI/src/views/acc/archive/view_files.vue index 8d8a9dd..7b462d8 100644 --- a/webUI/src/views/acc/archive/view_files.vue +++ b/webUI/src/views/acc/archive/view_files.vue @@ -1,171 +1,180 @@