v6 update

This commit is contained in:
Mohit Panjwani
2022-01-10 16:06:17 +05:30
parent b770e6277f
commit bdea879273
722 changed files with 19047 additions and 9186 deletions

View File

@ -0,0 +1,312 @@
<template>
<BasePage>
<BasePageHeader :title="pageTitle">
<BaseBreadcrumb>
<BaseBreadcrumbItem :title="$t('general.home')" to="dashboard" />
<BaseBreadcrumbItem :title="$tc('items.item', 2)" to="/admin/items" />
<BaseBreadcrumbItem :title="pageTitle" to="#" active />
</BaseBreadcrumb>
</BasePageHeader>
<ItemUnitModal />
<form
class="grid lg:grid-cols-2 mt-6"
action="submit"
@submit.prevent="submitItem"
>
<BaseCard class="w-full">
<BaseInputGrid layout="one-column">
<BaseInputGroup
:label="$t('items.name')"
:content-loading="isFetchingInitialData"
required
:error="
v$.currentItem.name.$error &&
v$.currentItem.name.$errors[0].$message
"
>
<BaseInput
v-model="itemStore.currentItem.name"
:content-loading="isFetchingInitialData"
:invalid="v$.currentItem.name.$error"
@input="v$.currentItem.name.$touch()"
/>
</BaseInputGroup>
<BaseInputGroup
:label="$t('items.price')"
:content-loading="isFetchingInitialData"
>
<BaseMoney
v-model="price"
:content-loading="isFetchingInitialData"
/>
</BaseInputGroup>
<BaseInputGroup
:content-loading="isFetchingInitialData"
:label="$t('items.unit')"
>
<BaseMultiselect
v-model="itemStore.currentItem.unit_id"
:content-loading="isFetchingInitialData"
label="name"
:options="itemStore.itemUnits"
value-prop="id"
:can-deselect="false"
:can-clear="false"
:placeholder="$t('items.select_a_unit')"
searchable
track-by="name"
>
<template #action>
<BaseSelectAction @click="addItemUnit">
<BaseIcon
name="PlusIcon"
class="h-4 mr-2 -ml-2 text-center text-primary-400"
/>
{{ $t('settings.customization.items.add_item_unit') }}
</BaseSelectAction>
</template>
</BaseMultiselect>
</BaseInputGroup>
<BaseInputGroup
v-if="isTaxPerItem"
:label="$t('items.taxes')"
:content-loading="isFetchingInitialData"
>
<BaseMultiselect
v-model="taxes"
:content-loading="isFetchingInitialData"
:options="getTaxTypes"
mode="tags"
label="tax_name"
class="w-full"
value-prop="id"
:can-deselect="false"
:can-clear="false"
searchable
track-by="tax_name"
object
/>
</BaseInputGroup>
<BaseInputGroup
:label="$t('items.description')"
:content-loading="isFetchingInitialData"
:error="
v$.currentItem.description.$error &&
v$.currentItem.description.$errors[0].$message
"
>
<BaseTextarea
v-model="itemStore.currentItem.description"
:content-loading="isFetchingInitialData"
name="description"
:row="2"
rows="2"
@input="v$.currentItem.description.$touch()"
/>
</BaseInputGroup>
<div>
<BaseButton
:content-loading="isFetchingInitialData"
type="submit"
:loading="isSaving"
>
<template #left="slotProps">
<BaseIcon
v-if="!isSaving"
name="SaveIcon"
:class="slotProps.class"
/>
</template>
{{ isEdit ? $t('items.update_item') : $t('items.save_item') }}
</BaseButton>
</div>
</BaseInputGrid>
</BaseCard>
</form>
</BasePage>
</template>
<script setup>
import { computed, ref } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useI18n } from 'vue-i18n'
import {
required,
minLength,
numeric,
minValue,
maxLength,
helpers,
} from '@vuelidate/validators'
import useVuelidate from '@vuelidate/core'
import { useItemStore } from '@/scripts/admin/stores/item'
import { useCompanyStore } from '@/scripts/admin/stores/company'
import { useTaxTypeStore } from '@/scripts/admin/stores/tax-type'
import { useModalStore } from '@/scripts/stores/modal'
import ItemUnitModal from '@/scripts/admin/components/modal-components/ItemUnitModal.vue'
import { useUserStore } from '@/scripts/admin/stores/user'
import abilities from '@/scripts/admin/stub/abilities'
const itemStore = useItemStore()
const taxTypeStore = useTaxTypeStore()
const modalStore = useModalStore()
const companyStore = useCompanyStore()
const { t } = useI18n()
const route = useRoute()
const router = useRouter()
const userStore = useUserStore()
const isSaving = ref(false)
const taxPerItem = ref(companyStore.selectedCompanySettings.tax_per_item)
let isFetchingInitialData = ref(false)
itemStore.$reset()
loadData()
const price = computed({
get: () => itemStore.currentItem.price / 100,
set: (value) => {
itemStore.currentItem.price = Math.round(value * 100)
},
})
const taxes = computed({
get: () =>
itemStore?.currentItem?.taxes?.map((tax) => {
if (tax) {
return {
...tax,
tax_type_id: tax.id,
tax_name: tax.name + ' (' + tax.percent + '%)',
}
}
}),
set: (value) => {
itemStore.currentItem.taxes = value
},
})
const isEdit = computed(() => route.name === 'items.edit')
const pageTitle = computed(() =>
isEdit.value ? t('items.edit_item') : t('items.new_item')
)
const getTaxTypes = computed(() => {
return taxTypeStore.taxTypes.map((tax) => {
return {
...tax,
tax_type_id: tax.id,
tax_name: tax.name + ' (' + tax.percent + '%)',
}
})
})
const isTaxPerItem = computed(() => taxPerItem.value === 'YES')
const rules = computed(() => {
return {
currentItem: {
name: {
required: helpers.withMessage(t('validation.required'), required),
minLength: helpers.withMessage(
t('validation.name_min_length', { count: 3 }),
minLength(3)
),
},
description: {
maxLength: helpers.withMessage(
t('validation.description_maxlength'),
maxLength(65000)
),
},
},
}
})
const v$ = useVuelidate(rules, itemStore)
async function addItemUnit() {
modalStore.openModal({
title: t('settings.customization.items.add_item_unit'),
componentName: 'ItemUnitModal',
size: 'sm',
})
}
async function loadData() {
isFetchingInitialData.value = true
await itemStore.fetchItemUnits({ limit: 'all' })
if (userStore.hasAbilities(abilities.VIEW_TAX_TYPE)) {
await taxTypeStore.fetchTaxTypes({ limit: 'all' })
}
if (isEdit.value) {
let id = route.params.id
await itemStore.fetchItem(id)
itemStore.currentItem.tax_per_item === 1
? (taxPerItem.value = 'YES')
: (taxPerItem.value = 'NO')
}
isFetchingInitialData.value = false
}
async function submitItem() {
v$.value.currentItem.$touch()
if (v$.value.currentItem.$invalid) {
return false
}
isSaving.value = true
try {
let data = {
id: route.params.id,
...itemStore.currentItem,
}
if (itemStore.currentItem && itemStore.currentItem.taxes) {
data.taxes = itemStore.currentItem.taxes.map((tax) => {
return {
tax_type_id: tax.tax_type_id,
amount: price.value * tax.percent,
percent: tax.percent,
name: tax.name,
collective_tax: 0,
}
})
}
const action = isEdit.value ? itemStore.updateItem : itemStore.addItem
await action(data)
isSaving.value = false
router.push('/admin/items')
closeItemModal()
} catch (err) {
isSaving.value = false
return
}
function closeItemModal() {
modalStore.closeModal()
setTimeout(() => {
itemStore.resetCurrentItem()
modalStore.$reset()
v$.value.$reset()
}, 300)
}
}
</script>

View File

@ -0,0 +1,359 @@
<template>
<BasePage>
<BasePageHeader :title="$t('items.title')">
<BaseBreadcrumb>
<BaseBreadcrumbItem :title="$t('general.home')" to="dashboard" />
<BaseBreadcrumbItem :title="$tc('items.item', 2)" to="#" active />
</BaseBreadcrumb>
<template #actions>
<div class="flex items-center justify-end space-x-5">
<BaseButton
v-show="itemStore.totalItems"
variant="primary-outline"
@click="toggleFilter"
>
{{ $t('general.filter') }}
<template #right="slotProps">
<BaseIcon
v-if="!showFilters"
:class="slotProps.class"
name="FilterIcon"
/>
<BaseIcon v-else name="XIcon" :class="slotProps.class" />
</template>
</BaseButton>
<BaseButton
v-if="userStore.hasAbilities(abilities.CREATE_ITEM)"
@click="$router.push('/admin/items/create')"
>
<template #left="slotProps">
<BaseIcon name="PlusIcon" :class="slotProps.class" />
</template>
{{ $t('items.add_item') }}
</BaseButton>
</div>
</template>
</BasePageHeader>
<BaseFilterWrapper :show="showFilters" class="mt-5" @clear="clearFilter">
<BaseInputGroup :label="$tc('items.name')" class="text-left">
<BaseInput
v-model="filters.name"
type="text"
name="name"
autocomplete="off"
/>
</BaseInputGroup>
<BaseInputGroup :label="$tc('items.unit')" class="text-left">
<BaseMultiselect
v-model="filters.unit_id"
:placeholder="$t('items.select_a_unit')"
value-prop="id"
track-by="name"
:filter-results="false"
label="name"
resolve-on-load
:delay="500"
searchable
class="w-full"
:options="searchUnits"
/>
</BaseInputGroup>
<BaseInputGroup class="text-left" :label="$tc('items.price')">
<BaseMoney v-model="filters.price" />
</BaseInputGroup>
</BaseFilterWrapper>
<BaseEmptyPlaceholder
v-show="showEmptyScreen"
:title="$t('items.no_items')"
:description="$t('items.list_of_items')"
>
<SatelliteIcon class="mt-5 mb-4" />
<template #actions>
<BaseButton
v-if="userStore.hasAbilities(abilities.CREATE_ITEM)"
variant="primary-outline"
@click="$router.push('/admin/items/create')"
>
<template #left="slotProps">
<BaseIcon name="PlusIcon" :class="slotProps.class" />
</template>
{{ $t('items.add_new_item') }}
</BaseButton>
</template>
</BaseEmptyPlaceholder>
<div v-show="!showEmptyScreen" class="relative table-container">
<div
class="
relative
flex
items-center
justify-end
h-5
border-gray-200 border-solid
"
>
<BaseDropdown v-if="itemStore.selectedItems.length">
<template #activator>
<span
class="
flex
text-sm
font-medium
cursor-pointer
select-none
text-primary-400
"
>
{{ $t('general.actions') }}
<BaseIcon name="ChevronDownIcon" />
</span>
</template>
<BaseDropdownItem @click="removeMultipleItems">
<BaseIcon name="TrashIcon" class="mr-3 text-gray-600" />
{{ $t('general.delete') }}
</BaseDropdownItem>
</BaseDropdown>
</div>
<BaseTable
ref="table"
:data="fetchData"
:columns="itemColumns"
:placeholder-count="itemStore.totalItems >= 20 ? 10 : 5"
class="mt-3"
>
<template #header>
<div class="absolute items-center left-6 top-2.5 select-none">
<BaseCheckbox
v-model="itemStore.selectAllField"
variant="primary"
@change="itemStore.selectAllItems"
/>
</div>
</template>
<template #cell-status="{ row }">
<div class="relative block">
<BaseCheckbox
:id="row.id"
v-model="selectField"
:value="row.data.id"
/>
</div>
</template>
<template #cell-name="{ row }">
<router-link
:to="{ path: `items/${row.data.id}/edit` }"
class="font-medium text-primary-500"
>
{{ row.data.name }}
</router-link>
</template>
<template #cell-unit_name="{ row }">
<span>
{{ row.data.unit ? row.data.unit.name : '-' }}
</span>
</template>
<template #cell-price="{ row }">
<BaseFormatMoney
:amount="row.data.price"
:currency="companyStore.selectedCompanyCurrency"
/>
</template>
<template #cell-created_at="{ row }">
<span>{{ row.data.formatted_created_at }}</span>
</template>
<template v-if="hasAbilities()" #cell-actions="{ row }">
<ItemDropdown
:row="row.data"
:table="table"
:load-data="refreshTable"
/>
</template>
</BaseTable>
</div>
</BasePage>
</template>
<script setup>
import { ref, computed, inject, onMounted, reactive, onUnmounted } from 'vue'
import { debouncedWatch } from '@vueuse/core'
import { useI18n } from 'vue-i18n'
import { useItemStore } from '@/scripts/admin/stores/item'
import { useNotificationStore } from '@/scripts/stores/notification'
import { useDialogStore } from '@/scripts/stores/dialog'
import { useCompanyStore } from '@/scripts/admin/stores/company'
import { useUserStore } from '@/scripts/admin/stores/user'
import ItemDropdown from '@/scripts/admin/components/dropdowns/ItemIndexDropdown.vue'
import SatelliteIcon from '@/scripts/components/icons/empty/SatelliteIcon.vue'
import abilities from '@/scripts/admin/stub/abilities'
const utils = inject('utils')
const itemStore = useItemStore()
const companyStore = useCompanyStore()
const notificationStore = useNotificationStore()
const dialogStore = useDialogStore()
const userStore = useUserStore()
const { t } = useI18n()
let showFilters = ref(false)
let isFetchingInitialData = ref(true)
const filters = reactive({
name: '',
unit_id: '',
price: '',
})
const table = ref(null)
const showEmptyScreen = computed(
() => !itemStore.totalItems && !isFetchingInitialData.value
)
const selectField = computed({
get: () => itemStore.selectedItems,
set: (value) => {
return itemStore.selectItem(value)
},
})
const itemColumns = computed(() => {
return [
{
key: 'status',
thClass: 'extra w-10',
tdClass: 'font-medium text-gray-900',
placeholderClass: 'w-10',
sortable: false,
},
{
key: 'name',
label: t('items.name'),
thClass: 'extra',
tdClass: 'font-medium text-gray-900',
},
{ key: 'unit_name', label: t('items.unit') },
{ key: 'price', label: t('items.price') },
{ key: 'created_at', label: t('items.added_on') },
{
key: 'actions',
thClass: 'text-right',
tdClass: 'text-right text-sm font-medium',
sortable: false,
},
]
})
debouncedWatch(
filters,
() => {
setFilters()
},
{ debounce: 500 }
)
itemStore.fetchItemUnits({ limit: 'all' })
onUnmounted(() => {
if (itemStore.selectAllField) {
itemStore.selectAllItems()
}
})
function clearFilter() {
filters.name = ''
filters.unit_id = ''
filters.price = ''
}
function hasAbilities() {
return userStore.hasAbilities([abilities.DELETE_ITEM, abilities.EDIT_ITEM])
}
function toggleFilter() {
if (showFilters.value) {
clearFilter()
}
showFilters.value = !showFilters.value
}
function refreshTable() {
table.value && table.value.refresh()
}
function setFilters() {
refreshTable()
}
async function searchUnits(search) {
let res = await itemStore.fetchItemUnits({ search })
return res.data.data
}
async function fetchData({ page, filter, sort }) {
let data = {
search: filters.name,
unit_id: filters.unit_id !== null ? filters.unit_id : '',
price: Math.round(filters.price * 100),
orderByField: sort.fieldName || 'created_at',
orderBy: sort.order || 'desc',
page,
}
isFetchingInitialData.value = true
let response = await itemStore.fetchItems(data)
isFetchingInitialData.value = false
return {
data: response.data.data,
pagination: {
totalPages: response.data.meta.last_page,
currentPage: page,
totalCount: response.data.meta.total,
limit: 10,
},
}
}
function removeMultipleItems() {
dialogStore
.openDialog({
title: t('general.are_you_sure'),
message: t('items.confirm_delete', 2),
yesLabel: t('general.ok'),
noLabel: t('general.cancel'),
variant: 'danger',
hideNoButton: false,
size: 'lg',
})
.then((res) => {
if (res) {
itemStore.deleteMultipleItems().then((response) => {
if (response.data.success) {
table.value && table.value.refresh()
}
})
}
})
}
</script>