hesabixCore/webUI/src/views/acc/settings/bussiness.vue

923 lines
41 KiB
Vue
Executable file

<template>
<v-toolbar color="toolbar" :title="$t('dialog.bid_info')">
<template v-slot:prepend>
<v-tooltip :text="$t('dialog.back')" location="bottom">
<template v-slot:activator="{ props }">
<v-btn v-bind="props" @click="$router.back()" class="d-none d-sm-flex" variant="text"
icon="mdi-arrow-right" />
</template>
</v-tooltip>
</template>
<v-spacer></v-spacer>
<v-btn :loading="loading" @click="submit()" icon="" color="green">
<v-tooltip activator="parent" :text="$t('dialog.save')" location="bottom" />
<v-icon icon="mdi-content-save"></v-icon>
</v-btn>
<template v-slot:extension>
<v-tabs color="primary" class="bg-light" grow v-model="tabs">
<v-tab value="0">
{{ $t('dialog.basic_info') }}
</v-tab>
<v-tab value="1">
{{ $t('dialog.year_label') }}
</v-tab>
<v-tab value="2">
{{ $t('dialog.global_settings') }}
</v-tab>
<v-tab value="3" v-if="showBackupTab">
نسخه پشتیبان
</v-tab>
</v-tabs>
</template>
</v-toolbar>
<v-row class="pa-1">
<v-col>
<v-tabs-window v-model="tabs">
<v-tabs-window-item value="0">
<v-card>
<v-card-text>
<h3 class="text-primary">اطلاعات کسب و کار</h3>
<v-row>
<v-col cols="12" md="6">
<v-text-field
v-model="content.name"
label="نام کسب و کار"
variant="outlined"
required
density="compact"
></v-text-field>
</v-col>
<v-col cols="12" md="6">
<v-text-field
v-model="content.legal_name"
label="نام قانونی کسب و کار"
variant="outlined"
required
density="compact"
></v-text-field>
</v-col>
<v-col cols="12" md="6">
<v-text-field
v-model="content.field"
label="زمینه فعالیت"
variant="outlined"
density="compact"
></v-text-field>
</v-col>
<v-col cols="12" md="6">
<v-select
v-model="content.type"
:items="['شرکت', 'مغازه', 'فروشگاه', 'اتحادیه', 'باشگاه', 'موسسه', 'شخصی']"
label="نوع فعالیت"
variant="outlined"
density="compact"
></v-select>
</v-col>
</v-row>
<h3 class="text-primary mt-4">اطلاعات اقتصادی</h3>
<v-row>
<v-col cols="12" md="6">
<v-text-field
v-model="content.shenasemeli"
label="شناسه ملی"
variant="outlined"
density="compact"
></v-text-field>
</v-col>
<v-col cols="12" md="6">
<v-text-field
v-model="content.codeeqtesadi"
label="کد اقتصادی"
variant="outlined"
density="compact"
></v-text-field>
</v-col>
<v-col cols="12" md="6">
<v-text-field
v-model="content.shomaresabt"
label="شماره ثبت"
variant="outlined"
density="compact"
></v-text-field>
</v-col>
</v-row>
<h3 class="text-primary mt-4">اطلاعات تماس</h3>
<v-row>
<v-col cols="12" md="4">
<v-text-field
v-model="content.country"
label="کشور"
variant="outlined"
density="compact"
></v-text-field>
</v-col>
<v-col cols="12" md="4">
<v-text-field
v-model="content.ostan"
label="استان"
variant="outlined"
density="compact"
></v-text-field>
</v-col>
<v-col cols="12" md="4">
<v-text-field
v-model="content.shahrestan"
label="شهر"
variant="outlined"
density="compact"
></v-text-field>
</v-col>
<v-col cols="12" md="4">
<v-text-field
v-model="content.postalcode"
label="کد پستی"
variant="outlined"
density="compact"
></v-text-field>
</v-col>
<v-col cols="12" md="4">
<v-text-field
v-model="content.tel"
label="تلفن"
variant="outlined"
density="compact"
></v-text-field>
</v-col>
<v-col cols="12" md="4">
<v-text-field
v-model="content.mobile"
label="موبایل"
variant="outlined"
density="compact"
></v-text-field>
</v-col>
<v-col cols="12">
<v-text-field
v-model="content.address"
label="آدرس"
variant="outlined"
density="compact"
></v-text-field>
</v-col>
<v-col cols="12" md="6">
<v-text-field
v-model="content.website"
label="وب‌سایت"
variant="outlined"
density="compact"
></v-text-field>
</v-col>
<v-col cols="12" md="6">
<v-text-field
v-model="content.email"
label="پست الکترونیکی"
variant="outlined"
density="compact"
></v-text-field>
</v-col>
</v-row>
<h3 class="text-primary mt-4">اطلاعات مالی</h3>
<v-row>
<v-col cols="12" md="6">
<v-text-field
v-model="content.maliyatafzode"
label="مالیات بر ارزش افزوده"
type="number"
variant="outlined"
required
density="compact"
></v-text-field>
</v-col>
</v-row>
</v-card-text>
</v-card>
</v-tabs-window-item>
<v-tabs-window-item value="1">
<v-card>
<v-card-text>
<h3 class="text-primary">سال مالی</h3>
<v-row>
<v-col cols="12" md="6">
<Hdatepicker
v-model="content.year.startShamsi"
label="شروع سال مالی"
:rules="[v => !!v || 'این فیلد الزامی است']"
:ignore-year-range="true"
/>
</v-col>
<v-col cols="12" md="6">
<Hdatepicker
v-model="content.year.endShamsi"
label="اتمام سال مالی"
:rules="[v => !!v || 'این فیلد الزامی است']"
:ignore-year-range="true"
:min="content.year.startShamsi"
/>
</v-col>
<v-col cols="12">
<v-text-field
v-model="content.year.label"
label="عنوان سال مالی"
variant="outlined"
required
density="compact"
></v-text-field>
</v-col>
</v-row>
</v-card-text>
</v-card>
</v-tabs-window-item>
<v-tabs-window-item value="2">
<v-card>
<v-card-text>
<h3 class="text-primary mb-6">تنظیمات سراسری کسب و کار</h3>
<v-row>
<v-col cols="12" md="8">
<!-- بخش پیوندهای یکتا -->
<v-card variant="outlined" class="mb-6">
<v-card-title class="text-h6 text-primary">
<v-icon icon="mdi-link-variant" class="mr-2"></v-icon>
نمایش پیوند یکتا
</v-card-title>
<v-card-text>
<v-switch
v-model="content.shortlinks"
label="فعال‌سازی پیوند‌های یکتا"
color="primary"
hide-details
class="mb-2"
></v-switch>
<div class="text-body-2 text-medium-emphasis">
این قابلیت برای تولید پیوند‌های یکتا برای ارسال به مشتری جهت مشاهده فاکتورها است.
</div>
</v-card-text>
</v-card>
<!-- بخش کیف پول -->
<v-card variant="outlined" class="mb-6">
<v-card-title class="text-h6 text-primary">
<v-icon icon="mdi-wallet" class="mr-2"></v-icon>
دریافت مبلغ فاکتور از طریق کیف پول
</v-card-title>
<v-card-text>
<v-switch
v-model="content.walletEnabled"
label="فعال‌سازی دریافت آنلاین از طریق کیف پول"
color="primary"
@change="checkBanksExist"
hide-details
class="mb-2"
></v-switch>
<div class="text-body-2 text-medium-emphasis mb-4">
با فعال سازی این قابلیت قادر خواهید بود مبالغ فاکتورهای ثبت شده را به صورت آنلاین از مشتریان خود دریافت کنید.
</div>
<v-expand-transition>
<div v-if="content.walletEnabled">
<v-divider class="mb-4"></v-divider>
<v-row>
<v-col cols="12" md="8">
<v-select
v-model="content.walletMatchBank"
:items="listBanks"
item-title="name"
item-value="id"
label="حساب بانکی متصل به کیف پول"
variant="outlined"
density="compact"
prepend-icon="mdi-bank"
></v-select>
</v-col>
<v-col cols="12">
<v-alert
type="info"
variant="tonal"
class="mt-2"
>
<template v-slot:prepend>
<v-icon icon="mdi-information"></v-icon>
</template>
برای تسویه اتوماتیک به حساب انتخاب شده حتما باید تمام موارد از جمله شماره شبا و شماره کارت و ... به درستی تکمیل شده باشد در غیر این صورت تراکنش با خطا مواجه خواهد شد.
</v-alert>
</v-col>
</v-row>
</div>
</v-expand-transition>
</v-card-text>
</v-card>
<!-- تایید دومرحله‌ای -->
<v-card v-if="isPluginActive('accpro')" variant="outlined" class="mb-6">
<v-card-title class="text-h6 text-primary">
<v-icon icon="mdi-shield-check" class="mr-2"></v-icon>
تایید دومرحله‌ای
</v-card-title>
<v-card-text>
<v-switch
v-model="content.requireTwoStepApproval"
label="فعال‌سازی تایید دومرحله‌ای برای اسناد"
color="primary"
hide-details
class="mb-2"
></v-switch>
<div class="text-body-2 text-medium-emphasis mb-2">
با فعال‌سازی این گزینه، تمام فاکتورها، حواله‌های انبار، دریافت‌ها و پرداخت‌ها نیاز به تایید مدیر خواهند داشت.
</div>
<v-expand-transition>
<div v-if="content.requireTwoStepApproval">
<v-divider class="my-4"></v-divider>
<h4 class="text-subtitle-1 mb-3">تعیین تاییدکنندگان</h4>
<v-row>
<v-col cols="12">
<v-select
v-model="content.invoiceApprover"
:items="users"
item-title="name"
item-value="email"
label="تاییدکننده فاکتور فروش"
variant="outlined"
density="compact"
clearable
hint="کاربری که می‌تواند فاکتورهای فروش را تایید کند"
persistent-hint
>
<template v-slot:item="{ item, props }">
<v-list-item v-bind="props">
<template v-slot:prepend>
<v-icon
:color="item.owner ? 'success' : 'primary'"
size="small"
>
{{ item.owner ? 'mdi-crown' : 'mdi-account' }}
</v-icon>
</template>
<v-list-item-title>{{ item.name }}</v-list-item-title>
<v-list-item-subtitle>{{ item.email }}</v-list-item-subtitle>
</v-list-item>
</template>
</v-select>
<div class="text-caption text-medium-emphasis mt-1">
این کاربر افزون بر مدیر کسب و کار می‌تواند فاکتورهای فروش را تایید کند
</div>
</v-col>
<v-col cols="12">
<v-select
v-model="content.warehouseApprover"
:items="users"
item-title="name"
item-value="email"
label="تاییدکننده حواله انبار"
variant="outlined"
density="compact"
clearable
hint="کاربری که می‌تواند حواله‌های انبار را تایید کند"
persistent-hint
>
<template v-slot:item="{ item, props }">
<v-list-item v-bind="props">
<template v-slot:prepend>
<v-icon
:color="item.owner ? 'success' : 'primary'"
size="small"
>
{{ item.owner ? 'mdi-crown' : 'mdi-account' }}
</v-icon>
</template>
<v-list-item-title>{{ item.name }}</v-list-item-title>
<v-list-item-subtitle>{{ item.email }}</v-list-item-subtitle>
</v-list-item>
</template>
</v-select>
<div class="text-caption text-medium-emphasis mt-1">
این کاربر افزون بر مدیر کسب و کار می‌تواند حواله‌های انبار را تایید کند
</div>
</v-col>
<!-- تاییدکننده دریافت و پرداخت مالی (غیرفعال فعلاً) -->
<!--
<v-col cols="12">
<v-select
v-model="content.financialApprover"
:items="users"
item-title="name"
item-value="email"
label="تاییدکننده دریافت و پرداخت مالی"
variant="outlined"
density="compact"
clearable
hint="کاربری که می‌تواند دریافت‌ها و پرداخت‌ها را تایید کند"
persistent-hint
/>
</v-col>
-->
</v-row>
<div class="text-caption text-medium-emphasis">
<v-icon size="small" color="info" class="me-1">mdi-information</v-icon>
در صورت عدم انتخاب تاییدکننده، فقط مدیر کسب و کار می‌تواند اسناد را تایید کند
</div>
<div class="text-caption text-medium-emphasis mt-2">
<v-icon size="small" color="success" class="me-1">mdi-check-circle</v-icon>
<strong>نکته:</strong> صاحب کسب و کار همیشه می‌تواند تمام اسناد را تأیید کند و نیازی به تعیین مجدد ندارد
</div>
</div>
</v-expand-transition>
</v-card-text>
</v-card>
<v-card variant="outlined">
<v-card-title class="text-h6 text-primary">
<v-icon icon="mdi-package-variant" class="mr-2"></v-icon>
کالا و خدمات
</v-card-title>
<v-card-text>
<v-row>
<v-col cols="12">
<v-switch
v-model="content.updateBuyPrice"
label="به روز رسانی قیمت خرید هنگام صدور فاکتور"
color="primary"
hide-details
class="mb-2"
></v-switch>
<div class="text-body-2 text-medium-emphasis mb-4">
با صدور فاکتور خرید یا برگشت از خرید قیمت خرید کالا و خدمات به روزرسانی خواهد شد.
</div>
</v-col>
<v-col cols="12">
<v-switch
v-model="content.updateSellPrice"
label="به روز رسانی قیمت فروش هنگام صدور فاکتور"
color="primary"
hide-details
class="mb-2"
></v-switch>
<div class="text-body-2 text-medium-emphasis mb-4">
با صدور فاکتور فروش یا برگشت از فروش قیمت فروش کالا و خدمات به روزرسانی خواهد شد.
</div>
</v-col>
<v-col cols="12" md="8">
<v-select
v-model="content.profitCalcType"
:items="[
{ title: 'بر اساس اختلاف قیمت خرید و فروش', value: 'simple' },
{ title: 'بر اساس آخرین قیمت ورود به انبار', value: 'lis' },
{ title: 'بر اساس میانگین قیمت ورود به انبار', value: 'avgis' }
]"
item-title="title"
item-value="value"
label="نحوه محاسبه سود فاکتور"
variant="outlined"
density="compact"
prepend-icon="mdi-calculator"
></v-select>
</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-help-circle" class="mr-2"></v-icon>
راهنما
</v-card-title>
<v-card-text>
<v-list density="compact">
<v-list-item prepend-icon="mdi-link-variant" title="پیوند یکتا" class="text-body-2">
<template v-slot:subtitle>
<span class="text-caption">برای اشتراک‌گذاری فاکتورها</span>
</template>
</v-list-item>
<v-list-item prepend-icon="mdi-wallet" title="کیف پول" class="text-body-2">
<template v-slot:subtitle>
<span class="text-caption">دریافت آنلاین مبالغ</span>
</template>
</v-list-item>
<v-list-item prepend-icon="mdi-package-variant" title="کالا و خدمات" class="text-body-2">
<template v-slot:subtitle>
<span class="text-caption">مدیریت قیمت‌ها و سود</span>
</template>
</v-list-item>
</v-list>
</v-card-text>
</v-card>
<!-- کارت نکات مهم -->
<v-card variant="outlined" color="info">
<v-card-title class="text-h6">
<v-icon icon="mdi-lightbulb" class="mr-2"></v-icon>
نکات مهم
</v-card-title>
<v-card-text>
<div class="text-body-2">
<ul class="pl-4">
<li class="mb-2">تنظیمات سراسری بر تمام عملیات کسب و کار تأثیر می‌گذارد</li>
<li class="mb-2">تغییرات پس از ذخیره اعمال می‌شوند</li>
<li class="mb-2">برای کیف پول حتماً حساب بانکی معتبر انتخاب کنید</li>
</ul>
</div>
</v-card-text>
</v-card>
</v-col>
</v-row>
</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>
</template>
<script>
import axios from "axios";
import Swal from "sweetalert2";
import Hdatepicker from "@/components/forms/Hdatepicker.vue";
export default {
name: "bussiness",
components: {
Hdatepicker
},
data: () => {
return {
tabs: '',
loading: false,
backupLoading: false,
showBackupTab: false,
moneys: [],
content: {
name: '',
legal_name: '',
field: '',
type: 'مغازه',
shenasemeli: '',
codeeqtesadi: '',
shomaresabt: '',
country: '',
ostan: '',
shahrestan: '',
postalcode: '',
tel: '',
mobile: '',
address: '',
website: '',
email: '',
arzmain: [],
maliyatafzode: 9,
shortlinks: false,
walletEnabled: false,
walletMatchBank: null,
requireTwoStepApproval: false,
invoiceApprover: null,
warehouseApprover: null,
financialApprover: null,
year: {
startShamsi: '',
endShamsi: '',
label: ''
},
updateSellPrice: false,
updateBuyPrice: false,
profitCalcType: 'lis'
},
users: [],
listBanks: [],
plugins: []
}
},
watch: {
'content.year.endShamsi': {
handler(newVal) {
if (newVal) {
this.content.year.label = `سال مالی منتهی به ${newVal}`;
}
}
}
},
methods: {
isPluginActive(plugName) {
return this.plugins[plugName] !== undefined;
},
checkBanksExist() {
if (this.listBanks.length === 0) {
Swal.fire({
text: 'هنوز هیچ حساب بانکی تعریف نشده است.',
icon: 'error',
confirmButtonText: 'تعریف حساب جدید',
cancelButtonText: 'بازگشت',
showCancelButton: true
}).then((res) => {
if (res.isConfirmed) {
this.$router.push('/acc/banks/mod/');
}
else {
this.content.walletEnabled = false;
}
});
}
},
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({
text: 'تکمیل موارد ستاره دار الزامی است.',
icon: 'error',
confirmButtonText: 'قبول'
});
return;
}
if (this.content.walletEnabled && (this.content.walletMatchBank === undefined || this.content.walletMatchBank === null)) {
Swal.fire({
text: 'حساب بانکی متصل به کیف پول انتخاب نشده است',
icon: 'error',
confirmButtonText: 'قبول'
});
return;
}
//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,
'requireTwoStepApproval': this.content.requireTwoStepApproval,
'invoiceApprover': this.content.invoiceApprover,
'warehouseApprover': this.content.warehouseApprover,
'financialApprover': this.content.financialApprover,
'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: 'قبول'
});
}
})
.catch((error) => {
this.loading = false;
Swal.fire({
text: 'خطا در ثبت اطلاعات',
icon: 'error',
confirmButtonText: 'قبول'
});
});
}
},
async beforeMount() {
this.loading = true
try {
// ابتدا اطلاعات کسب و کار را بارگذاری کن
const businessResponse = await axios.post('/api/business/get/info/' + localStorage.getItem('activeBid'));
this.content = businessResponse.data;
// اگر walletMatchBank یک آبجکت است، فقط id آن را نگه می‌داریم
if (this.content.walletMatchBank && typeof this.content.walletMatchBank === 'object') {
this.content.walletMatchBank = this.content.walletMatchBank.id;
}
// اطمینان از وجود فیلدهای تأییدکننده
if (!this.content.hasOwnProperty('invoiceApprover')) {
this.content.invoiceApprover = null;
}
if (!this.content.hasOwnProperty('warehouseApprover')) {
this.content.warehouseApprover = null;
}
if (!this.content.hasOwnProperty('financialApprover')) {
this.content.financialApprover = null;
}
if (!this.content.hasOwnProperty('requireTwoStepApproval')) {
this.content.requireTwoStepApproval = false;
}
// سپس سایر داده‌ها را بارگذاری کن
const [moneyResponse, banksResponse, usersResponse, pluginsResponse] = await Promise.all([
axios.post("/api/money/get/all"),
axios.post('/api/bank/list'),
axios.get(`/api/user/get/users/of/business/${localStorage.getItem('activeBid')}`),
axios.post(`/api/plugin/get/actives`)
]);
this.plugins = pluginsResponse.data;
this.moneys = moneyResponse.data;
this.content.arzmain = this.moneys[0];
this.listBanks = banksResponse.data;
// حذف صاحب کسب و کار از لیست کاربران تأییدکننده
this.users = usersResponse.data.filter(user => !user.owner);
} catch (error) {
console.error('Error loading data:', error);
Swal.fire({
text: 'خطا در بارگذاری اطلاعات',
icon: 'error',
confirmButtonText: 'قبول'
});
} finally {
try {
// بررسی دسترسی settings و فعال بودن افزونه accpro و نمایش تب پشتیبان
const permissionsResponse = await axios.post('/api/business/get/user/permissions');
if (permissionsResponse.data.settings) {
const pluginResponse = await axios.post('/api/plugin/check/accpro/' + localStorage.getItem('activeBid'));
this.showBackupTab = !!pluginResponse.data.active;
} else {
this.showBackupTab = false;
}
} catch (permErr) {
console.error('خطا در بررسی دسترسی‌ها:', permErr);
this.showBackupTab = false;
} finally {
this.loading = false;
}
}
}
}
</script>
<style scoped>
.required label:before {
content: "*";
color: red;
}
</style>