/
TaxTypesSetting.vue
162 lines (141 loc) · 4.12 KB
/
TaxTypesSetting.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<template>
<BaseSettingCard
:title="$t('settings.tax_types.title')"
:description="$t('settings.tax_types.description')"
>
<TaxTypeModal />
<template v-if="userStore.hasAbilities(abilities.CREATE_TAX_TYPE)" #action>
<BaseButton type="submit" variant="primary-outline" @click="openTaxModal">
<template #left="slotProps">
<BaseIcon :class="slotProps.class" name="PlusIcon" />
</template>
{{ $t('settings.tax_types.add_new_tax') }}
</BaseButton>
</template>
<BaseTable
ref="table"
class="mt-16"
:data="fetchData"
:columns="taxTypeColumns"
>
<template #cell-percent="{ row }"> {{ row.data.percent }} % </template>
<template v-if="hasAtleastOneAbility()" #cell-actions="{ row }">
<TaxTypeDropdown
:row="row.data"
:table="table"
:load-data="refreshTable"
/>
</template>
</BaseTable>
<div v-if="userStore.currentUser.is_owner">
<BaseDivider class="mt-8 mb-2" />
<BaseSwitchSection
v-model="taxPerItemField"
:disabled="salesTaxEnabled"
:title="$t('settings.tax_types.tax_per_item')"
:description="$t('settings.tax_types.tax_setting_description')"
/>
</div>
</BaseSettingCard>
</template>
<script setup>
import { useTaxTypeStore } from '@/scripts/admin/stores/tax-type'
import { useModalStore } from '@/scripts/stores/modal'
import { computed, reactive, ref, inject } from 'vue'
import { useI18n } from 'vue-i18n'
import { useCompanyStore } from '@/scripts/admin/stores/company'
import { useUserStore } from '@/scripts/admin/stores/user'
import { useModuleStore } from '@/scripts/admin/stores/module'
import TaxTypeDropdown from '@/scripts/admin/components/dropdowns/TaxTypeIndexDropdown.vue'
import TaxTypeModal from '@/scripts/admin/components/modal-components/TaxTypeModal.vue'
import abilities from '@/scripts/admin/stub/abilities'
const { t } = useI18n()
const utils = inject('utils')
const companyStore = useCompanyStore()
const taxTypeStore = useTaxTypeStore()
const modalStore = useModalStore()
const userStore = useUserStore()
const moduleStore = useModuleStore()
const table = ref(null)
const taxPerItemSetting = ref(companyStore.selectedCompanySettings.tax_per_item)
const taxTypeColumns = computed(() => {
return [
{
key: 'name',
label: t('settings.tax_types.tax_name'),
thClass: 'extra',
tdClass: 'font-medium text-gray-900',
},
{
key: 'percent',
label: t('settings.tax_types.percent'),
thClass: 'extra',
tdClass: 'font-medium text-gray-900',
},
{
key: 'actions',
label: '',
tdClass: 'text-right text-sm font-medium',
sortable: false,
},
]
})
const salesTaxEnabled = computed(() => {
return (
companyStore.selectedCompanySettings.sales_tax_us_enabled === 'YES' &&
moduleStore.salesTaxUSEnabled
)
})
const taxPerItemField = computed({
get: () => {
return taxPerItemSetting.value === 'YES'
},
set: async (newValue) => {
const value = newValue ? 'YES' : 'NO'
let data = {
settings: {
tax_per_item: value,
},
}
taxPerItemSetting.value = value
await companyStore.updateCompanySettings({
data,
message: 'general.setting_updated',
})
},
})
function hasAtleastOneAbility() {
return userStore.hasAbilities([
abilities.DELETE_TAX_TYPE,
abilities.EDIT_TAX_TYPE,
])
}
async function fetchData({ page, filter, sort }) {
let data = {
orderByField: sort.fieldName || 'created_at',
orderBy: sort.order || 'desc',
page,
}
let response = await taxTypeStore.fetchTaxTypes(data)
return {
data: response.data.data,
pagination: {
totalPages: response.data.meta.last_page,
currentPage: page,
totalCount: response.data.meta.total,
limit: 5,
},
}
}
async function refreshTable() {
table.value && table.value.refresh()
}
function openTaxModal() {
modalStore.openModal({
title: t('settings.tax_types.add_tax'),
componentName: 'TaxTypeModal',
size: 'sm',
refreshData: table.value && table.value.refresh,
})
}
</script>