add backup in excell in accpro plugin

This commit is contained in:
Hesabix 2025-08-13 15:04:04 +00:00
parent 290b272872
commit 251ebe59f7
3 changed files with 1106 additions and 46 deletions

View file

@ -0,0 +1,885 @@
<?php
namespace App\Controller;
use App\Entity\Business;
use App\Entity\Permission;
use App\Entity\User;
use App\Service\Access;
use App\Service\Extractor;
use App\Service\PluginService;
use Doctrine\ORM\EntityManagerInterface;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\CurrentUser;
class BackupController extends AbstractController
{
#[Route('/api/backup/create', name: 'api_backup_create', methods: ['POST'])]
public function createBackup(
Request $request,
#[CurrentUser] ?User $user,
Access $access,
PluginService $pluginService,
EntityManagerInterface $entityManager
): Response {
// بررسی دسترسی settings
$acc = $access->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++;
}
}
}

View file

@ -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]);
}
/**
* بررسی دسترسی کاربر با نقش مشخص
*

View file

@ -24,6 +24,9 @@
<v-tab value="2">
{{ $t('dialog.global_settings') }}
</v-tab>
<v-tab value="3" v-if="showBackupTab">
نسخه پشتیبان
</v-tab>
</v-tabs>
</template>
</v-toolbar>
@ -323,6 +326,111 @@
</v-card-text>
</v-card>
</v-tabs-window-item>
<v-tabs-window-item value="3" v-if="showBackupTab">
<v-card>
<v-card-text>
<h3 class="text-primary mb-4">نسخه پشتیبان از اطلاعات کسب و کار</h3>
<v-row>
<v-col cols="12" md="8">
<v-card variant="outlined" class="mb-6">
<v-card-text>
<div class="text-body-1 text-medium-emphasis mb-4">
با استفاده از این قابلیت میتوانید از تمام اطلاعات کسب و کار خود نسخه پشتیبان تهیه کنید.
فایل خروجی در قالب اکسل خواهد بود و شامل تمام اطلاعات مهم کسب و کار شما میباشد.
</div>
<v-btn
:loading="backupLoading"
@click="createBackup()"
color="primary"
variant="elevated"
size="large"
prepend-icon="mdi-download"
class="mb-4"
>
ایجاد نسخه پشتیبان
</v-btn>
<div class="text-body-2 text-medium-emphasis">
<v-icon icon="mdi-information" class="mr-2" color="info"></v-icon>
فایل اکسل شامل اطلاعات زیر خواهد بود:
</div>
</v-card-text>
</v-card>
<v-card variant="outlined">
<v-card-title class="text-h6 text-primary">
<v-icon icon="mdi-file-excel" class="mr-2"></v-icon>
محتوای فایل نسخه پشتیبان
</v-card-title>
<v-card-text>
<v-row>
<v-col cols="12" md="6">
<h4 class="text-subtitle-1 text-primary mb-3">اطلاعات پایه</h4>
<v-list density="compact" class="bg-grey-lighten-5 rounded">
<v-list-item prepend-icon="mdi-information" title="اطلاعات کسب و کار" class="text-body-2"></v-list-item>
<v-list-item prepend-icon="mdi-account-group" title="اشخاص" class="text-body-2"></v-list-item>
<v-list-item prepend-icon="mdi-package-variant" title="کالاها" class="text-body-2"></v-list-item>
<v-list-item prepend-icon="mdi-bank" title="حساب‌های بانکی" class="text-body-2"></v-list-item>
</v-list>
</v-col>
<v-col cols="12" md="6">
<h4 class="text-subtitle-1 text-primary mb-3">اطلاعات مالی</h4>
<v-list density="compact" class="bg-grey-lighten-5 rounded">
<v-list-item prepend-icon="mdi-file-document" title="اسناد حسابداری" class="text-body-2"></v-list-item>
<v-list-item prepend-icon="mdi-calculator" title="جدول حساب‌ها" class="text-body-2"></v-list-item>
<v-list-item prepend-icon="mdi-format-list-bulleted" title="تراکنش‌ها" class="text-body-2"></v-list-item>
</v-list>
</v-col>
</v-row>
<v-row class="mt-4">
<v-col cols="12" md="6">
<h4 class="text-subtitle-1 text-primary mb-3">فاکتورها</h4>
<v-list density="compact" class="bg-grey-lighten-5 rounded">
<v-list-item prepend-icon="mdi-cart" title="فاکتورهای فروش" class="text-body-2"></v-list-item>
<v-list-item prepend-icon="mdi-cart-arrow-up" title="فاکتورهای خرید" class="text-body-2"></v-list-item>
<v-list-item prepend-icon="mdi-cart-remove" title="برگشت از خرید" class="text-body-2"></v-list-item>
<v-list-item prepend-icon="mdi-cart-return" title="برگشت از فروش" class="text-body-2"></v-list-item>
</v-list>
</v-col>
<v-col cols="12" md="6">
<h4 class="text-subtitle-1 text-primary mb-3">سایر اطلاعات</h4>
<v-list density="compact" class="bg-grey-lighten-5 rounded">
<v-list-item prepend-icon="mdi-warehouse" title="انبار" class="text-body-2"></v-list-item>
<v-list-item prepend-icon="mdi-cash-plus" title="دریافت از اشخاص" class="text-body-2"></v-list-item>
<v-list-item prepend-icon="mdi-cash-minus" title="پرداخت به اشخاص" class="text-body-2"></v-list-item>
</v-list>
</v-col>
</v-row>
</v-card-text>
</v-card>
</v-col>
<v-col cols="12" md="4">
<v-card variant="outlined" class="mb-4">
<v-card-title class="text-h6 text-primary">
<v-icon icon="mdi-lightbulb" class="mr-2"></v-icon>
نکات مهم
</v-card-title>
<v-card-text>
<v-list density="compact">
<v-list-item prepend-icon="mdi-check-circle" title="فایل اکسل با فرمت استاندارد" class="text-body-2 text-success"></v-list-item>
<v-list-item prepend-icon="mdi-check-circle" title="شامل تمام اطلاعات مهم" class="text-body-2 text-success"></v-list-item>
<v-list-item prepend-icon="mdi-check-circle" title="قابل استفاده در نرم‌افزارهای دیگر" class="text-body-2 text-success"></v-list-item>
<v-list-item prepend-icon="mdi-check-circle" title="امن و قابل اعتماد" class="text-body-2 text-success"></v-list-item>
</v-list>
</v-card-text>
</v-card>
</v-col>
</v-row>
</v-card-text>
</v-card>
</v-tabs-window-item>
</v-tabs-window>
</v-col>
</v-row>
@ -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;
}
}
}
</script>