diff --git a/hesabixCore/src/Controller/BackupController.php b/hesabixCore/src/Controller/BackupController.php new file mode 100644 index 0000000..4568973 --- /dev/null +++ b/hesabixCore/src/Controller/BackupController.php @@ -0,0 +1,885 @@ +hasRole('settings'); + if (!$acc) { + throw $this->createAccessDeniedException(); + } + + // بررسی فعال بودن افزونه accpro + if (!$pluginService->isActive('accpro', $acc['bid'])) { + return $this->json([ + 'result' => 0, + 'message' => 'این قابلیت فقط برای کاربران افزونه accpro در دسترس است.' + ]); + } + + try { + // ایجاد فایل اکسل + $spreadsheet = new Spreadsheet(); + + // اطلاعات کسب و کار + $this->addBusinessInfoSheet($spreadsheet, $acc['bid'], $entityManager); + + // اطلاعات اشخاص + $this->addPersonsSheet($spreadsheet, $acc['bid'], $entityManager); + + // اطلاعات کالاها + $this->addCommoditiesSheet($spreadsheet, $acc['bid'], $entityManager); + + // اطلاعات حساب‌های بانکی + $this->addBankAccountsSheet($spreadsheet, $acc['bid'], $entityManager); + + // اطلاعات اسناد حسابداری + $this->addHesabdariDocsSheet($spreadsheet, $acc['bid'], $entityManager); + + // اطلاعات فاکتورهای فروش + $this->addSellDocsSheet($spreadsheet, $acc['bid'], $entityManager); + + // اطلاعات فاکتورهای خرید + $this->addBuyDocsSheet($spreadsheet, $acc['bid'], $entityManager); + + // اطلاعات انبار + $this->addStoreroomSheet($spreadsheet, $acc['bid'], $entityManager); + + // جدول حساب‌ها + $this->addHesabdariTableSheet($spreadsheet, $acc['bid'], $entityManager); + + // تراکنش‌ها + $this->addHesabdariRowSheet($spreadsheet, $acc['bid'], $entityManager); + + // دریافت از اشخاص + $this->addPersonReceiveSheet($spreadsheet, $acc['bid'], $entityManager); + + // پرداخت به اشخاص + $this->addPersonSendSheet($spreadsheet, $acc['bid'], $entityManager); + + // برگشت از خرید + $this->addRfBuySheet($spreadsheet, $acc['bid'], $entityManager); + + // برگشت از فروش + $this->addRfSellSheet($spreadsheet, $acc['bid'], $entityManager); + + // حذف sheet پیش‌فرض + $spreadsheet->removeSheetByIndex(0); + + // ایجاد فایل + $writer = new Xlsx($spreadsheet); + $filename = 'backup_' . $acc['bid']->getName() . '_' . date('Y-m-d_H-i-s') . '.xlsx'; + $filepath = sys_get_temp_dir() . '/' . $filename; + $writer->save($filepath); + + // ارسال فایل + $response = $this->file($filepath, $filename, ResponseHeaderBag::DISPOSITION_ATTACHMENT); + + // حذف فایل موقت بعد از ارسال response + $response->deleteFileAfterSend(true); + + return $response; + + } catch (\Exception $e) { + return $this->json([ + 'result' => 0, + 'message' => 'خطا در ایجاد نسخه پشتیبان: ' . $e->getMessage() + ]); + } + } + + private function addBusinessInfoSheet(Spreadsheet $spreadsheet, Business $business, EntityManagerInterface $entityManager): void + { + $sheet = $spreadsheet->createSheet(); + $sheet->setTitle('اطلاعات کسب و کار'); + + // هدرها + $headers = [ + 'نام کسب و کار', + 'نام قانونی', + 'زمینه فعالیت', + 'نوع فعالیت', + 'شناسه ملی', + 'کد اقتصادی', + 'شماره ثبت', + 'کشور', + 'استان', + 'شهر', + 'کد پستی', + 'تلفن', + 'موبایل', + 'آدرس', + 'وب‌سایت', + 'ایمیل', + 'مالیات بر ارزش افزوده', + 'تاریخ ثبت' + ]; + + $col = 'A'; + foreach ($headers as $header) { + $sheet->setCellValue($col . '1', $header); + $col++; + } + + // داده‌ها + $data = [ + $business->getName(), + $business->getLegalName(), + $business->getField(), + $business->getType(), + $business->getShenasemeli(), + $business->getCodeeghtesadi(), + $business->getShomaresabt(), + $business->getCountry(), + $business->getOstan(), + $business->getShahrestan(), + $business->getPostalcode(), + $business->getTel(), + $business->getMobile(), + $business->getAddress(), + $business->getWesite(), + $business->getEmail(), + $business->getMaliyatafzode(), + date('Y-m-d H:i:s', $business->getDateSubmit()) + ]; + + $col = 'A'; + foreach ($data as $value) { + $sheet->setCellValue($col . '2', $value); + $col++; + } + } + + private function addPersonsSheet(Spreadsheet $spreadsheet, Business $business, EntityManagerInterface $entityManager): void + { + $sheet = $spreadsheet->createSheet(); + $sheet->setTitle('اشخاص'); + + // هدرها + $headers = [ + 'نام', + 'نام خانوادگی', + 'کد', + 'نوع', + 'تلفن', + 'موبایل', + 'ایمیل', + 'آدرس', + 'کد ملی', + 'کد اقتصادی', + 'تاریخ ثبت' + ]; + + $col = 'A'; + foreach ($headers as $header) { + $sheet->setCellValue($col . '1', $header); + $col++; + } + + // دریافت اشخاص + $persons = $entityManager->getRepository(\App\Entity\Person::class)->findBy(['bid' => $business]); + + $row = 2; + foreach ($persons as $person) { + $data = [ + $person->getName(), + $person->getNikename(), + $person->getCode(), + $person->getType() ? $person->getType()->first() ? $person->getType()->first()->getName() : '' : '', + $person->getTel(), + $person->getMobile(), + $person->getEmail(), + $person->getAddress(), + $person->getShenasemeli(), + $person->getCodeeghtesadi(), + '' // Entity Person فیلد تاریخ ثبت ندارد + ]; + + $col = 'A'; + foreach ($data as $value) { + $sheet->setCellValue($col . $row, $value); + $col++; + } + $row++; + } + } + + private function addCommoditiesSheet(Spreadsheet $spreadsheet, Business $business, EntityManagerInterface $entityManager): void + { + $sheet = $spreadsheet->createSheet(); + $sheet->setTitle('کالاها'); + + // هدرها + $headers = [ + 'نام کالا', + 'کد', + 'دسته‌بندی', + 'واحد', + 'قیمت خرید', + 'قیمت فروش', + 'موجودی', + 'حداقل سفارش', + 'توضیحات', + 'تاریخ ثبت' + ]; + + $col = 'A'; + foreach ($headers as $header) { + $sheet->setCellValue($col . '1', $header); + $col++; + } + + // دریافت کالاها + $commodities = $entityManager->getRepository(\App\Entity\Commodity::class)->findBy(['bid' => $business]); + + $row = 2; + foreach ($commodities as $commodity) { + $data = [ + $commodity->getName(), + $commodity->getCode(), + $commodity->getCat() ? $commodity->getCat()->getName() : '', + $commodity->getUnit() ? $commodity->getUnit()->getName() : '', + $commodity->getPriceBuy(), + $commodity->getPriceSell(), + '', // Entity Commodity فیلد موجودی ندارد + $commodity->getMinOrderCount(), // حداقل سفارش + $commodity->getDes(), + '' // Entity Commodity فیلد تاریخ ثبت ندارد + ]; + + $col = 'A'; + foreach ($data as $value) { + $sheet->setCellValue($col . $row, $value); + $col++; + } + $row++; + } + } + + private function addBankAccountsSheet(Spreadsheet $spreadsheet, Business $business, EntityManagerInterface $entityManager): void + { + $sheet = $spreadsheet->createSheet(); + $sheet->setTitle('حساب‌های بانکی'); + + // هدرها + $headers = [ + 'نام حساب', + 'شماره حساب', + 'شماره کارت', + 'شماره شبا', + 'نام صاحب حساب', + 'موجودی', + 'توضیحات', + 'تاریخ ثبت' + ]; + + $col = 'A'; + foreach ($headers as $header) { + $sheet->setCellValue($col . '1', $header); + $col++; + } + + // دریافت حساب‌های بانکی + $bankAccounts = $entityManager->getRepository(\App\Entity\BankAccount::class)->findBy(['bid' => $business]); + + $row = 2; + foreach ($bankAccounts as $account) { + $data = [ + $account->getName(), + $account->getAccountNum(), + $account->getCardNum(), + $account->getShaba(), + $account->getOwner(), + $account->getBalance(), + $account->getDes(), + '' // Entity BankAccount فیلد تاریخ ثبت ندارد + ]; + + $col = 'A'; + foreach ($data as $value) { + $sheet->setCellValue($col . $row, $value); + $col++; + } + $row++; + } + } + + private function addHesabdariDocsSheet(Spreadsheet $spreadsheet, Business $business, EntityManagerInterface $entityManager): void + { + $sheet = $spreadsheet->createSheet(); + $sheet->setTitle('اسناد حسابداری'); + + // هدرها + $headers = [ + 'شماره سند', + 'تاریخ', + 'سال مالی', + 'نوع سند', + 'شرح', + 'مبلغ', + 'حساب بدهکار', + 'حساب بستانکار', + 'وضعیت', + 'تاریخ ثبت' + ]; + + $col = 'A'; + foreach ($headers as $header) { + $sheet->setCellValue($col . '1', $header); + $col++; + } + + // دریافت اسناد حسابداری + $docs = $entityManager->getRepository(\App\Entity\HesabdariDoc::class)->findBy(['bid' => $business]); + + $row = 2; + foreach ($docs as $doc) { + // دریافت ردیف‌های حسابداری این سند + $rows = $doc->getHesabdariRows(); + $debitAccounts = []; + $creditAccounts = []; + + foreach ($rows as $hesabdariRow) { + $accountName = $hesabdariRow->getRef() ? $hesabdariRow->getRef()->getName() . ' (' . $hesabdariRow->getRef()->getCode() . ')' : ''; + + if ($hesabdariRow->getBd() && $hesabdariRow->getBd() > 0) { + $debitAccounts[] = $accountName; + } + if ($hesabdariRow->getBs() && $hesabdariRow->getBs() > 0) { + $creditAccounts[] = $accountName; + } + } + + $data = [ + $doc->getCode(), + $doc->getDate(), + $doc->getYear() ? $doc->getYear()->getLabel() : '', + $doc->getType(), + $doc->getDes(), + $doc->getAmount(), + implode(', ', array_unique($debitAccounts)), + implode(', ', array_unique($creditAccounts)), + $doc->getStatus(), + $doc->getDateSubmit() + ]; + + $col = 'A'; + foreach ($data as $value) { + $sheet->setCellValue($col . $row, $value); + $col++; + } + $row++; + } + } + + private function addSellDocsSheet(Spreadsheet $spreadsheet, Business $business, EntityManagerInterface $entityManager): void + { + $sheet = $spreadsheet->createSheet(); + $sheet->setTitle('فاکتورهای فروش'); + + // هدرها + $headers = [ + 'شماره فاکتور', + 'تاریخ', + 'سال مالی', + 'مشتری', + 'مبلغ کل', + 'درصد مالیات', + 'تخفیف', + 'مبلغ نهایی', + 'وضعیت', + 'تاریخ ثبت' + ]; + + $col = 'A'; + foreach ($headers as $header) { + $sheet->setCellValue($col . '1', $header); + $col++; + } + + // دریافت فاکتورهای فروش + $docs = $entityManager->getRepository(\App\Entity\HesabdariDoc::class)->findBy([ + 'bid' => $business, + 'type' => 'sell' + ]); + + $row = 2; + foreach ($docs as $doc) { + $data = [ + $doc->getCode(), + $doc->getDate(), + $doc->getYear() ? $doc->getYear()->getLabel() : '', + $doc->getSalesman() ? $doc->getSalesman()->getName() . ' ' . $doc->getSalesman()->getNikename() : '', + $doc->getAmount(), + $doc->getTaxPercent(), + '', // Entity فیلد تخفیف ندارد + $doc->getAmount(), // مبلغ نهایی همان مبلغ کل است + $doc->getStatus(), + $doc->getDateSubmit() + ]; + + $col = 'A'; + foreach ($data as $value) { + $sheet->setCellValue($col . $row, $value); + $col++; + } + $row++; + } + } + + private function addBuyDocsSheet(Spreadsheet $spreadsheet, Business $business, EntityManagerInterface $entityManager): void + { + $sheet = $spreadsheet->createSheet(); + $sheet->setTitle('فاکتورهای خرید'); + + // هدرها + $headers = [ + 'شماره فاکتور', + 'تاریخ', + 'سال مالی', + 'فروشنده', + 'مبلغ کل', + 'درصد مالیات', + 'تخفیف', + 'مبلغ نهایی', + 'وضعیت', + 'تاریخ ثبت' + ]; + + $col = 'A'; + foreach ($headers as $header) { + $sheet->setCellValue($col . '1', $header); + $col++; + } + + // دریافت فاکتورهای خرید + $docs = $entityManager->getRepository(\App\Entity\HesabdariDoc::class)->findBy([ + 'bid' => $business, + 'type' => 'buy' + ]); + + $row = 2; + foreach ($docs as $doc) { + $data = [ + $doc->getCode(), + $doc->getDate(), + $doc->getYear() ? $doc->getYear()->getLabel() : '', + $doc->getSalesman() ? $doc->getSalesman()->getName() . ' ' . $doc->getSalesman()->getNikename() : '', + $doc->getAmount(), + $doc->getTaxPercent(), + '', // Entity فیلد تخفیف ندارد + $doc->getAmount(), // مبلغ نهایی همان مبلغ کل است + $doc->getStatus(), + $doc->getDateSubmit() + ]; + + $col = 'A'; + foreach ($data as $value) { + $sheet->setCellValue($col . $row, $value); + $col++; + } + $row++; + } + } + + private function addStoreroomSheet(Spreadsheet $spreadsheet, Business $business, EntityManagerInterface $entityManager): void + { + $sheet = $spreadsheet->createSheet(); + $sheet->setTitle('انبار'); + + // هدرها + $headers = [ + 'نام انبار', + 'شناسه', + 'آدرس', + 'مسئول', + 'وضعیت', + 'تاریخ ثبت' + ]; + + $col = 'A'; + foreach ($headers as $header) { + $sheet->setCellValue($col . '1', $header); + $col++; + } + + // دریافت انبارها + $storerooms = $entityManager->getRepository(\App\Entity\Storeroom::class)->findBy(['bid' => $business]); + + $row = 2; + foreach ($storerooms as $storeroom) { + $data = [ + $storeroom->getName(), + $storeroom->getId(), + $storeroom->getAdr(), + $storeroom->getManager(), + $storeroom->isActive() ? 'فعال' : 'غیرفعال', + '' // Entity Storeroom فیلد تاریخ ثبت ندارد + ]; + + $col = 'A'; + foreach ($data as $value) { + $sheet->setCellValue($col . $row, $value); + $col++; + } + $row++; + } + } + + private function addHesabdariTableSheet(Spreadsheet $spreadsheet, Business $business, EntityManagerInterface $entityManager): void + { + $sheet = $spreadsheet->createSheet(); + $sheet->setTitle('جدول حساب‌ها'); + + // هدرها + $headers = [ + 'کد حساب', + 'نام حساب', + 'نوع حساب', + 'حساب والد', + 'نوع موجودیت', + 'وضعیت' + ]; + + $col = 'A'; + foreach ($headers as $header) { + $sheet->setCellValue($col . '1', $header); + $col++; + } + + // دریافت حساب‌ها + $accounts = $entityManager->getRepository(\App\Entity\HesabdariTable::class)->findBy(['bid' => $business]); + + $row = 2; + foreach ($accounts as $account) { + $data = [ + $account->getCode(), + $account->getName(), + $account->getType(), + $account->getUpper() ? $account->getUpper()->getName() . ' (' . $account->getUpper()->getCode() . ')' : '', + $account->getEntity(), + $account->getUpper() ? 'زیرمجموعه' : 'حساب اصلی' + ]; + + $col = 'A'; + foreach ($data as $value) { + $sheet->setCellValue($col . $row, $value); + $col++; + } + $row++; + } + } + + private function addHesabdariRowSheet(Spreadsheet $spreadsheet, Business $business, EntityManagerInterface $entityManager): void + { + $sheet = $spreadsheet->createSheet(); + $sheet->setTitle('تراکنش‌ها'); + + // هدرها + $headers = [ + 'شماره سند', + 'تاریخ سند', + 'سال مالی', + 'نوع سند', + 'حساب', + 'کد حساب', + 'بدهکار', + 'بستانکار', + 'شخص', + 'حساب بانکی', + 'کالا', + 'تعداد کالا', + 'توضیحات', + 'مرجع', + 'داده مرجع', + 'تخفیف', + 'مالیات', + 'نوع تخفیف', + 'درصد تخفیف' + ]; + + $col = 'A'; + foreach ($headers as $header) { + $sheet->setCellValue($col . '1', $header); + $col++; + } + + // دریافت تمام تراکنش‌ها + $rows = $entityManager->getRepository(\App\Entity\HesabdariRow::class)->findBy(['bid' => $business]); + + $row = 2; + foreach ($rows as $hesabdariRow) { + $doc = $hesabdariRow->getDoc(); + $data = [ + $doc ? $doc->getCode() : '', + $doc ? $doc->getDate() : '', + $hesabdariRow->getYear() ? $hesabdariRow->getYear()->getLabel() : '', + $doc ? $doc->getType() : '', + $hesabdariRow->getRef() ? $hesabdariRow->getRef()->getName() : '', + $hesabdariRow->getRef() ? $hesabdariRow->getRef()->getCode() : '', + $hesabdariRow->getBd() ?: '', + $hesabdariRow->getBs() ?: '', + $hesabdariRow->getPerson() ? $hesabdariRow->getPerson()->getName() . ' ' . $hesabdariRow->getPerson()->getNikename() : '', + $hesabdariRow->getBank() ? $hesabdariRow->getBank()->getName() : '', + $hesabdariRow->getCommodity() ? $hesabdariRow->getCommodity()->getName() : '', + $hesabdariRow->getCommdityCount() ?: '', + $hesabdariRow->getDes() ?: '', + $hesabdariRow->getReferral() ?: '', + $hesabdariRow->getRefData() ?: '', + $hesabdariRow->getDiscount() ?: '', + $hesabdariRow->getTax() ?: '', + $hesabdariRow->getDiscountType() ?: '', + $hesabdariRow->getDiscountPercent() ?: '' + ]; + + $col = 'A'; + foreach ($data as $value) { + $sheet->setCellValue($col . $row, $value); + $col++; + } + $row++; + } + } + + private function addPersonReceiveSheet(Spreadsheet $spreadsheet, Business $business, EntityManagerInterface $entityManager): void + { + $sheet = $spreadsheet->createSheet(); + $sheet->setTitle('دریافت از اشخاص'); + + // هدرها + $headers = [ + 'شماره سند', + 'تاریخ', + 'سال مالی', + 'شخص', + 'مبلغ', + 'واحد پول', + 'توضیحات', + 'وضعیت', + 'تاریخ ثبت' + ]; + + $col = 'A'; + foreach ($headers as $header) { + $sheet->setCellValue($col . '1', $header); + $col++; + } + + // دریافت اسناد دریافت از اشخاص + $docs = $entityManager->getRepository(\App\Entity\HesabdariDoc::class)->findBy([ + 'bid' => $business, + 'type' => 'person_receive' + ]); + + $row = 2; + foreach ($docs as $doc) { + $data = [ + $doc->getCode(), + $doc->getDate(), + $doc->getYear() ? $doc->getYear()->getLabel() : '', + $doc->getSalesman() ? $doc->getSalesman()->getName() . ' ' . $doc->getSalesman()->getNikename() : '', + $doc->getAmount(), + $doc->getMoney() ? $doc->getMoney()->getName() : '', + $doc->getDes(), + $doc->getStatus(), + $doc->getDateSubmit() + ]; + + $col = 'A'; + foreach ($data as $value) { + $sheet->setCellValue($col . $row, $value); + $col++; + } + $row++; + } + } + + private function addPersonSendSheet(Spreadsheet $spreadsheet, Business $business, EntityManagerInterface $entityManager): void + { + $sheet = $spreadsheet->createSheet(); + $sheet->setTitle('پرداخت به اشخاص'); + + // هدرها + $headers = [ + 'شماره سند', + 'تاریخ', + 'سال مالی', + 'شخص', + 'مبلغ', + 'واحد پول', + 'توضیحات', + 'وضعیت', + 'تاریخ ثبت' + ]; + + $col = 'A'; + foreach ($headers as $header) { + $sheet->setCellValue($col . '1', $header); + $col++; + } + + // دریافت اسناد پرداخت به اشخاص + $docs = $entityManager->getRepository(\App\Entity\HesabdariDoc::class)->findBy([ + 'bid' => $business, + 'type' => 'person_send' + ]); + + $row = 2; + foreach ($docs as $doc) { + $data = [ + $doc->getCode(), + $doc->getDate(), + $doc->getYear() ? $doc->getYear()->getLabel() : '', + $doc->getSalesman() ? $doc->getSalesman()->getName() . ' ' . $doc->getSalesman()->getNikename() : '', + $doc->getAmount(), + $doc->getMoney() ? $doc->getMoney()->getName() : '', + $doc->getDes(), + $doc->getStatus(), + $doc->getDateSubmit() + ]; + + $col = 'A'; + foreach ($data as $value) { + $sheet->setCellValue($col . $row, $value); + $col++; + } + $row++; + } + } + + private function addRfBuySheet(Spreadsheet $spreadsheet, Business $business, EntityManagerInterface $entityManager): void + { + $sheet = $spreadsheet->createSheet(); + $sheet->setTitle('برگشت از خرید'); + + // هدرها + $headers = [ + 'شماره فاکتور', + 'تاریخ', + 'سال مالی', + 'فروشنده', + 'مبلغ کل', + 'درصد مالیات', + 'تخفیف', + 'مبلغ نهایی', + 'وضعیت', + 'تاریخ ثبت' + ]; + + $col = 'A'; + foreach ($headers as $header) { + $sheet->setCellValue($col . '1', $header); + $col++; + } + + // دریافت فاکتورهای برگشت از خرید + $docs = $entityManager->getRepository(\App\Entity\HesabdariDoc::class)->findBy([ + 'bid' => $business, + 'type' => 'rfbuy' + ]); + + $row = 2; + foreach ($docs as $doc) { + $data = [ + $doc->getCode(), + $doc->getDate(), + $doc->getYear() ? $doc->getYear()->getLabel() : '', + $doc->getSalesman() ? $doc->getSalesman()->getName() . ' ' . $doc->getSalesman()->getNikename() : '', + $doc->getAmount(), + $doc->getTaxPercent(), + '', // Entity فیلد تخفیف ندارد + $doc->getAmount(), // مبلغ نهایی همان مبلغ کل است + $doc->getStatus(), + $doc->getDateSubmit() + ]; + + $col = 'A'; + foreach ($data as $value) { + $sheet->setCellValue($col . $row, $value); + $col++; + } + $row++; + } + } + + private function addRfSellSheet(Spreadsheet $spreadsheet, Business $business, EntityManagerInterface $entityManager): void + { + $sheet = $spreadsheet->createSheet(); + $sheet->setTitle('برگشت از فروش'); + + // هدرها + $headers = [ + 'شماره فاکتور', + 'تاریخ', + 'سال مالی', + 'مشتری', + 'مبلغ کل', + 'درصد مالیات', + 'تخفیف', + 'مبلغ نهایی', + 'وضعیت', + 'تاریخ ثبت' + ]; + + $col = 'A'; + foreach ($headers as $header) { + $sheet->setCellValue($col . '1', $header); + $col++; + } + + // دریافت فاکتورهای برگشت از فروش + $docs = $entityManager->getRepository(\App\Entity\HesabdariDoc::class)->findBy([ + 'bid' => $business, + 'type' => 'rfsell' + ]); + + $row = 2; + foreach ($docs as $doc) { + $data = [ + $doc->getCode(), + $doc->getDate(), + $doc->getYear() ? $doc->getYear()->getLabel() : '', + $doc->getSalesman() ? $doc->getSalesman()->getName() . ' ' . $doc->getSalesman()->getNikename() : '', + $doc->getAmount(), + $doc->getTaxPercent(), + '', // Entity فیلد تخفیف ندارد + $doc->getAmount(), // مبلغ نهایی همان مبلغ کل است + $doc->getStatus(), + $doc->getDateSubmit() + ]; + + $col = 'A'; + foreach ($data as $value) { + $sheet->setCellValue($col . $row, $value); + $col++; + } + $row++; + } + } +} \ No newline at end of file diff --git a/hesabixCore/src/Controller/PluginController.php b/hesabixCore/src/Controller/PluginController.php index 8aa4fdd..02d7908 100644 --- a/hesabixCore/src/Controller/PluginController.php +++ b/hesabixCore/src/Controller/PluginController.php @@ -4,7 +4,9 @@ namespace App\Controller; use App\Entity\Plugin; use App\Entity\PluginProdect; +use App\Entity\Business; use App\Service\Access; +use App\Service\PluginService; use App\Service\Extractor; use App\Service\Jdate; use App\Service\Log; @@ -23,6 +25,23 @@ class PluginController extends AbstractController { private const PRICE_MULTIPLIER = 10; // ضریب قیمت به صورت ثابت برای محاسبه تبدیل تومان به ریال + #[Route('/api/plugin/check/{plugin}/{bid}', name: 'api_plugin_check')] + public function api_plugin_check($plugin, $bid,Access $access, PluginService $pluginService, EntityManagerInterface $entityManager): Response + { + $acc = $access->hasRole('join'); + if (!$acc) { + return $this->json(['active' => false]); + } + + $business = $entityManager->getRepository(Business::class)->find($bid); + if (!$business) { + return $this->json(['active' => false]); + } + + $isActive = $pluginService->isActive($plugin, $business); + return $this->json(['active' => $isActive]); + } + /** * بررسی دسترسی کاربر با نقش مشخص * diff --git a/webUI/src/views/acc/settings/bussiness.vue b/webUI/src/views/acc/settings/bussiness.vue index fb7db39..ad9850d 100755 --- a/webUI/src/views/acc/settings/bussiness.vue +++ b/webUI/src/views/acc/settings/bussiness.vue @@ -24,6 +24,9 @@ {{ $t('dialog.global_settings') }} + + نسخه پشتیبان + @@ -323,6 +326,111 @@ + + + +

نسخه پشتیبان از اطلاعات کسب و کار

+ + + + + +
+ با استفاده از این قابلیت می‌توانید از تمام اطلاعات کسب و کار خود نسخه پشتیبان تهیه کنید. + فایل خروجی در قالب اکسل خواهد بود و شامل تمام اطلاعات مهم کسب و کار شما می‌باشد. +
+ + + ایجاد نسخه پشتیبان + + +
+ + فایل اکسل شامل اطلاعات زیر خواهد بود: +
+
+
+ + + + + محتوای فایل نسخه پشتیبان + + + + +

اطلاعات پایه

+ + + + + + +
+ + +

اطلاعات مالی

+ + + + + +
+
+ + + +

فاکتورها

+ + + + + + +
+ + +

سایر اطلاعات

+ + + + + +
+
+
+
+
+ + + + + + نکات مهم + + + + + + + + + + + + +
+
+
+
@@ -341,7 +449,9 @@ export default { data: () => { return { tabs: '', - loading : false, + loading: false, + backupLoading: false, + showBackupTab: false, moneys: [], content: { name: '', @@ -405,6 +515,39 @@ export default { }); } }, + async createBackup() { + this.backupLoading = true; + try { + const response = await axios.post('/api/backup/create', {}, { + responseType: 'blob' + }); + + // ایجاد لینک دانلود + const url = window.URL.createObjectURL(new Blob([response.data])); + const link = document.createElement('a'); + link.href = url; + link.setAttribute('download', `backup_${this.content.name}_${new Date().toISOString().slice(0, 19).replace(/:/g, '-')}.xlsx`); + document.body.appendChild(link); + link.click(); + link.remove(); + window.URL.revokeObjectURL(url); + + Swal.fire({ + text: 'نسخه پشتیبان با موفقیت ایجاد شد.', + icon: 'success', + confirmButtonText: 'قبول' + }); + } catch (error) { + console.error('خطا در ایجاد نسخه پشتیبان:', error); + Swal.fire({ + text: 'خطا در ایجاد نسخه پشتیبان', + icon: 'error', + confirmButtonText: 'قبول' + }); + } finally { + this.backupLoading = false; + } + }, submit() { if (this.content.year.label === '' || this.content.name === '' || this.content.legal_name === '' || this.content.maliyatafzode === '') { Swal.fire({ @@ -423,55 +566,55 @@ export default { return; } - //submit data - this.loading = true; + //submit data + this.loading = true; let data = { - 'bid': localStorage.getItem('activeBid'), - 'name': this.content.name, - 'legal_name': this.content.legal_name, - 'field': this.content.field, - 'type': this.content.type, - 'shenasemeli': this.content.shenasemeli, - 'codeeqtesadi': this.content.codeeqtesadi, - 'shomaresabt': this.content.shomaresabt, - 'country': this.content.country, - 'ostan': this.content.ostan, - 'shahrestan': this.content.shahrestan, - 'postalcode': this.content.postalcode, - 'tel': this.content.tel, - 'mobile': this.content.mobile, - 'address': this.content.address, - 'website': this.content.website, - 'email': this.content.email, - 'arzmain': this.content.arzmain, - 'maliyatafzode': this.content.maliyatafzode, - 'shortlinks': this.content.shortlinks, - 'walletEnabled': this.content.walletEnabled, - 'walletMatchBank': this.content.walletMatchBank, - 'year': this.content.year, - 'commodityUpdateBuyPriceAuto': this.content.updateBuyPrice, - 'commodityUpdateSellPriceAuto': this.content.updateSellPrice, - 'profitCalcType': this.content.profitCalcType + 'bid': localStorage.getItem('activeBid'), + 'name': this.content.name, + 'legal_name': this.content.legal_name, + 'field': this.content.field, + 'type': this.content.type, + 'shenasemeli': this.content.shenasemeli, + 'codeeqtesadi': this.content.codeeqtesadi, + 'shomaresabt': this.content.shomaresabt, + 'country': this.content.country, + 'ostan': this.content.ostan, + 'shahrestan': this.content.shahrestan, + 'postalcode': this.content.postalcode, + 'tel': this.content.tel, + 'mobile': this.content.mobile, + 'address': this.content.address, + 'website': this.content.website, + 'email': this.content.email, + 'arzmain': this.content.arzmain, + 'maliyatafzode': this.content.maliyatafzode, + 'shortlinks': this.content.shortlinks, + 'walletEnabled': this.content.walletEnabled, + 'walletMatchBank': this.content.walletMatchBank, + 'year': this.content.year, + 'commodityUpdateBuyPriceAuto': this.content.updateBuyPrice, + 'commodityUpdateSellPriceAuto': this.content.updateSellPrice, + 'profitCalcType': this.content.profitCalcType }; axios.post('/api/business/insert', data) - .then((response) => { - this.loading = false; - if (response.data.result == 1) { - Swal.fire({ - text: 'با موفقیت ثبت شد.', - icon: 'success', - confirmButtonText: 'قبول', - }) - } - else if (response.data.result === 0) { - Swal.fire({ - text: 'تکمیل موارد ستاره دار الزامی است.', - icon: 'error', - confirmButtonText: 'قبول' - }); - } - }) + .then((response) => { + this.loading = false; + if (response.data.result == 1) { + Swal.fire({ + text: 'با موفقیت ثبت شد.', + icon: 'success', + confirmButtonText: 'قبول', + }) + } + else if (response.data.result === 0) { + Swal.fire({ + text: 'تکمیل موارد ستاره دار الزامی است.', + icon: 'error', + confirmButtonText: 'قبول' + }); + } + }) .catch((error) => { this.loading = false; Swal.fire({ @@ -505,6 +648,19 @@ export default { } this.loading = false; }); + + // بررسی دسترسی settings و فعال بودن افزونه accpro + try { + const permissionsResponse = await axios.post('/api/business/get/user/permissions'); + if (permissionsResponse.data.settings) { + // بررسی فعال بودن افزونه accpro + const pluginResponse = await axios.post('/api/plugin/check/accpro/' + localStorage.getItem('activeBid')); + this.showBackupTab = pluginResponse.data.active; + } + } catch (error) { + console.error('خطا در بررسی دسترسی‌ها:', error); + this.showBackupTab = false; + } } }