mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-28 20:21:10 -04:00
v6 update
This commit is contained in:
496
resources/scripts/admin/views/recurring-invoices/Index.vue
Normal file
496
resources/scripts/admin/views/recurring-invoices/Index.vue
Normal file
@ -0,0 +1,496 @@
|
||||
<template>
|
||||
<BasePage>
|
||||
<SendInvoiceModal />
|
||||
|
||||
<BasePageHeader :title="$t('recurring_invoices.title')">
|
||||
<BaseBreadcrumb>
|
||||
<BaseBreadcrumbItem :title="$t('general.home')" to="dashboard" />
|
||||
|
||||
<BaseBreadcrumbItem
|
||||
:title="$tc('recurring_invoices.invoice', 2)"
|
||||
to="#"
|
||||
active
|
||||
/>
|
||||
</BaseBreadcrumb>
|
||||
|
||||
<template #actions>
|
||||
<BaseButton
|
||||
v-show="recurringInvoiceStore.totalRecurringInvoices"
|
||||
variant="primary-outline"
|
||||
@click="toggleFilter"
|
||||
>
|
||||
{{ $t('general.filter') }}
|
||||
<template #right="slotProps">
|
||||
<BaseIcon
|
||||
v-if="!showFilters"
|
||||
name="FilterIcon"
|
||||
:class="slotProps.class"
|
||||
/>
|
||||
<BaseIcon v-else name="XIcon" :class="slotProps.class" />
|
||||
</template>
|
||||
</BaseButton>
|
||||
|
||||
<router-link
|
||||
v-if="userStore.hasAbilities(abilities.CREATE_RECURRING_INVOICE)"
|
||||
to="recurring-invoices/create"
|
||||
>
|
||||
<BaseButton variant="primary" class="ml-4">
|
||||
<template #left="slotProps">
|
||||
<BaseIcon name="PlusIcon" :class="slotProps.class" />
|
||||
</template>
|
||||
{{ $t('recurring_invoices.new_invoice') }}
|
||||
</BaseButton>
|
||||
</router-link>
|
||||
</template>
|
||||
</BasePageHeader>
|
||||
|
||||
<BaseFilterWrapper v-show="showFilters" @clear="clearFilter">
|
||||
<BaseInputGroup :label="$tc('customers.customer', 1)">
|
||||
<BaseCustomerSelectInput
|
||||
v-model="filters.customer_id"
|
||||
:placeholder="$t('customers.type_or_click')"
|
||||
value-prop="id"
|
||||
label="name"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup :label="$t('recurring_invoices.status')">
|
||||
<BaseMultiselect
|
||||
v-model="filters.status"
|
||||
:options="statusList"
|
||||
searchable
|
||||
:placeholder="$t('general.select_a_status')"
|
||||
@update:modelValue="setActiveTab"
|
||||
@remove="clearStatusSearch()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup :label="$t('general.from')">
|
||||
<BaseDatePicker
|
||||
v-model="filters.from_date"
|
||||
:calendar-button="true"
|
||||
calendar-button-icon="calendar"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<div
|
||||
class="hidden w-8 h-0 mx-4 border border-gray-400 border-solid xl:block"
|
||||
style="margin-top: 1.5rem"
|
||||
/>
|
||||
|
||||
<BaseInputGroup :label="$t('general.to')">
|
||||
<BaseDatePicker
|
||||
v-model="filters.to_date"
|
||||
:calendar-button="true"
|
||||
calendar-button-icon="calendar"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
</BaseFilterWrapper>
|
||||
|
||||
<BaseEmptyPlaceholder
|
||||
v-show="showEmptyScreen"
|
||||
:title="$t('recurring_invoices.no_invoices')"
|
||||
:description="$t('recurring_invoices.list_of_invoices')"
|
||||
>
|
||||
<MoonwalkerIcon class="mt-5 mb-4" />
|
||||
|
||||
<template
|
||||
v-if="userStore.hasAbilities(abilities.CREATE_RECURRING_INVOICE)"
|
||||
#actions
|
||||
>
|
||||
<BaseButton
|
||||
variant="primary-outline"
|
||||
@click="$router.push('/admin/recurring-invoices/create')"
|
||||
>
|
||||
<template #left="slotProps">
|
||||
<BaseIcon name="PlusIcon" :class="slotProps.class" />
|
||||
</template>
|
||||
{{ $t('recurring_invoices.add_new_invoice') }}
|
||||
</BaseButton>
|
||||
</template>
|
||||
</BaseEmptyPlaceholder>
|
||||
|
||||
<div v-show="!showEmptyScreen" class="relative table-container">
|
||||
<div
|
||||
class="
|
||||
relative
|
||||
flex
|
||||
items-center
|
||||
justify-between
|
||||
h-10
|
||||
mt-5
|
||||
list-none
|
||||
border-b-2 border-gray-200 border-solid
|
||||
"
|
||||
>
|
||||
<!-- Tabs -->
|
||||
<BaseTabGroup
|
||||
class="-mb-5"
|
||||
:default-index="currentStatusIndex"
|
||||
@change="setStatusFilter"
|
||||
>
|
||||
<BaseTab :title="$t('recurring_invoices.active')" filter="ACTIVE" />
|
||||
<BaseTab :title="$t('recurring_invoices.on_hold')" filter="ON_HOLD" />
|
||||
<BaseTab :title="$t('recurring_invoices.all')" filter="ALL" />
|
||||
</BaseTabGroup>
|
||||
|
||||
<BaseDropdown
|
||||
v-if="recurringInvoiceStore.selectedRecurringInvoices.length"
|
||||
class="absolute float-right"
|
||||
>
|
||||
<template #activator>
|
||||
<span
|
||||
class="
|
||||
flex
|
||||
text-sm
|
||||
font-medium
|
||||
cursor-pointer
|
||||
select-none
|
||||
text-primary-400
|
||||
"
|
||||
>
|
||||
{{ $t('general.actions') }}
|
||||
<BaseIcon name="ChevronDownIcon" class="h-5" />
|
||||
</span>
|
||||
</template>
|
||||
|
||||
<BaseDropdownItem @click="removeMultipleRecurringInvoices()">
|
||||
<BaseIcon name="TrashIcon" class="mr-3 text-gray-600" />
|
||||
{{ $t('general.delete') }}
|
||||
</BaseDropdownItem>
|
||||
</BaseDropdown>
|
||||
</div>
|
||||
|
||||
<BaseTable
|
||||
ref="table"
|
||||
:data="fetchData"
|
||||
:columns="invoiceColumns"
|
||||
:placeholder-count="
|
||||
recurringInvoiceStore.totalRecurringInvoices >= 20 ? 10 : 5
|
||||
"
|
||||
class="mt-10"
|
||||
>
|
||||
<!-- Select All Checkbox -->
|
||||
<template #header>
|
||||
<div class="absolute items-center left-6 top-2.5 select-none">
|
||||
<BaseCheckbox
|
||||
v-model="recurringInvoiceStore.selectAllField"
|
||||
variant="primary"
|
||||
@change="recurringInvoiceStore.selectAllRecurringInvoices"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #cell-checkbox="{ row }">
|
||||
<div class="relative block">
|
||||
<BaseCheckbox
|
||||
:id="row.id"
|
||||
v-model="selectField"
|
||||
:value="row.data.id"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Starts at -->
|
||||
<template #cell-starts_at="{ row }">
|
||||
{{ row.data.formatted_starts_at }}
|
||||
</template>
|
||||
|
||||
<!-- Customer -->
|
||||
<template #cell-customer="{ row }">
|
||||
<router-link :to="{ path: `recurring-invoices/${row.data.id}/view` }">
|
||||
<BaseText
|
||||
:text="row.data.customer.name"
|
||||
:length="30"
|
||||
tag="span"
|
||||
class="font-medium text-primary-500 flex flex-col"
|
||||
/>
|
||||
|
||||
<BaseText
|
||||
:text="
|
||||
row.data.customer.contact_name
|
||||
? row.data.customer.contact_name
|
||||
: ''
|
||||
"
|
||||
:length="30"
|
||||
tag="span"
|
||||
class="text-xs text-gray-400"
|
||||
/>
|
||||
</router-link>
|
||||
</template>
|
||||
|
||||
<!-- Frequency -->
|
||||
<template #cell-frequency="{ row }">
|
||||
{{ getFrequencyLabel(row.data.frequency) }}
|
||||
</template>
|
||||
|
||||
<!-- Status -->
|
||||
<template #cell-status="{ row }">
|
||||
<BaseRecurringInvoiceStatusBadge
|
||||
:status="row.data.status"
|
||||
class="px-3 py-1"
|
||||
>
|
||||
{{ row.data.status }}
|
||||
</BaseRecurringInvoiceStatusBadge>
|
||||
</template>
|
||||
|
||||
<!-- Amount -->
|
||||
<template #cell-total="{ row }">
|
||||
<BaseFormatMoney
|
||||
:amount="row.data.total"
|
||||
:currency="row.data.customer.currency"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<!-- Actions -->
|
||||
<template v-if="canViewActions" #cell-actions="{ row }">
|
||||
<RecurringInvoiceIndexDropdown :row="row.data" :table="table" />
|
||||
</template>
|
||||
</BaseTable>
|
||||
</div>
|
||||
</BasePage>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, onUnmounted, reactive, ref, watch, inject } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useCustomerStore } from '@/scripts/admin/stores/customer'
|
||||
import { useNotificationStore } from '@/scripts/stores/notification'
|
||||
import { useDialogStore } from '@/scripts/stores/dialog'
|
||||
import { useRecurringInvoiceStore } from '@/scripts/admin/stores/recurring-invoice'
|
||||
import { useUserStore } from '@/scripts/admin/stores/user'
|
||||
import { debouncedWatch } from '@vueuse/core'
|
||||
|
||||
import SendInvoiceModal from '@/scripts/admin/components/modal-components/SendInvoiceModal.vue'
|
||||
import RecurringInvoiceIndexDropdown from '@/scripts/admin/components/dropdowns/RecurringInvoiceIndexDropdown.vue'
|
||||
import MoonwalkerIcon from '@/scripts/components/icons/empty/MoonwalkerIcon.vue'
|
||||
import abilities from '@/scripts/admin/stub/abilities'
|
||||
|
||||
const recurringInvoiceStore = useRecurringInvoiceStore()
|
||||
const customerStore = useCustomerStore()
|
||||
const dialogStore = useDialogStore()
|
||||
const notificationStore = useNotificationStore()
|
||||
const userStore = useUserStore()
|
||||
|
||||
const table = ref(null)
|
||||
const { t } = useI18n()
|
||||
const showFilters = ref(false)
|
||||
const statusList = ref(['ACTIVE', 'ON_HOLD', 'ALL'])
|
||||
const isRequestOngoing = ref(true)
|
||||
const activeTab = ref('recurring-invoices.all')
|
||||
const router = useRouter()
|
||||
|
||||
let filters = reactive({
|
||||
customer_id: '',
|
||||
status: 'ACTIVE',
|
||||
from_date: '',
|
||||
to_date: '',
|
||||
})
|
||||
|
||||
const showEmptyScreen = computed(
|
||||
() => !recurringInvoiceStore.totalRecurringInvoices && !isRequestOngoing.value
|
||||
)
|
||||
|
||||
const selectField = computed({
|
||||
get: () => recurringInvoiceStore.selectedRecurringInvoices,
|
||||
set: (value) => {
|
||||
return recurringInvoiceStore.selectRecurringInvoice(value)
|
||||
},
|
||||
})
|
||||
|
||||
const invoiceColumns = computed(() => {
|
||||
return [
|
||||
{
|
||||
key: 'checkbox',
|
||||
thClass: 'extra',
|
||||
tdClass: 'font-medium text-gray-900',
|
||||
},
|
||||
{
|
||||
key: 'starts_at',
|
||||
label: t('recurring_invoices.starts_at'),
|
||||
thClass: 'extra',
|
||||
tdClass: 'font-medium',
|
||||
},
|
||||
{ key: 'customer', label: t('invoices.customer') },
|
||||
{ key: 'frequency', label: t('recurring_invoices.frequency.title') },
|
||||
{ key: 'status', label: t('invoices.status') },
|
||||
{ key: 'total', label: t('invoices.total') },
|
||||
{
|
||||
key: 'actions',
|
||||
label: t('recurring_invoices.action'),
|
||||
tdClass: 'text-right text-sm font-medium',
|
||||
thClass: 'text-right',
|
||||
sortable: false,
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
debouncedWatch(
|
||||
filters,
|
||||
() => {
|
||||
setFilters()
|
||||
},
|
||||
{ debounce: 500 }
|
||||
)
|
||||
|
||||
onUnmounted(() => {
|
||||
if (recurringInvoiceStore.selectAllField) {
|
||||
recurringInvoiceStore.selectAllRecurringInvoices()
|
||||
}
|
||||
})
|
||||
|
||||
const currentStatusIndex = computed(() => {
|
||||
return statusList.value.findIndex((status) => status === filters.status)
|
||||
})
|
||||
|
||||
function canViewActions() {
|
||||
return userStore.hasAbilities([
|
||||
abilities.DELETE_RECURRING_INVOICE,
|
||||
abilities.EDIT_RECURRING_INVOICE,
|
||||
abilities.VIEW_RECURRING_INVOICE,
|
||||
])
|
||||
}
|
||||
|
||||
function getFrequencyLabel(frequencyFormat) {
|
||||
const frequencyObj = recurringInvoiceStore.frequencies.find((frequency) => {
|
||||
return frequency.value === frequencyFormat
|
||||
})
|
||||
|
||||
return frequencyObj ? frequencyObj.label : `CUSTOM: ${frequencyFormat}`
|
||||
}
|
||||
|
||||
function refreshTable() {
|
||||
table.value && table.value.refresh()
|
||||
}
|
||||
|
||||
async function fetchData({ page, filter, sort }) {
|
||||
let data = {
|
||||
customer_id: filters.customer_id,
|
||||
status: filters.status,
|
||||
from_date: filters.from_date,
|
||||
to_date: filters.to_date,
|
||||
orderByField: sort.fieldName || 'created_at',
|
||||
orderBy: sort.order || 'desc',
|
||||
page,
|
||||
}
|
||||
|
||||
isRequestOngoing.value = true
|
||||
|
||||
let response = await recurringInvoiceStore.fetchRecurringInvoices(data)
|
||||
|
||||
isRequestOngoing.value = false
|
||||
|
||||
return {
|
||||
data: response.data.data,
|
||||
pagination: {
|
||||
totalPages: response.data.meta.last_page,
|
||||
currentPage: page,
|
||||
totalCount: response.data.meta.total,
|
||||
limit: 10,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
function setStatusFilter(val) {
|
||||
if (activeTab.value == val.title) {
|
||||
return true
|
||||
}
|
||||
|
||||
activeTab.value = val.title
|
||||
|
||||
switch (val.title) {
|
||||
case t('recurring_invoices.active'):
|
||||
filters.status = 'ACTIVE'
|
||||
break
|
||||
case t('recurring_invoices.on_hold'):
|
||||
filters.status = 'ON_HOLD'
|
||||
break
|
||||
case t('recurring_invoices.all'):
|
||||
filters.status = 'ALL'
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
function setFilters() {
|
||||
recurringInvoiceStore.$patch((state) => {
|
||||
state.selectedRecurringInvoices = []
|
||||
state.selectAllField = false
|
||||
})
|
||||
|
||||
refreshTable()
|
||||
}
|
||||
|
||||
function clearFilter() {
|
||||
filters.customer_id = ''
|
||||
filters.status = ''
|
||||
filters.from_date = ''
|
||||
filters.to_date = ''
|
||||
filters.invoice_number = ''
|
||||
activeTab.value = t('general.all')
|
||||
}
|
||||
|
||||
async function removeMultipleRecurringInvoices(id = null) {
|
||||
dialogStore
|
||||
.openDialog({
|
||||
title: t('general.are_you_sure'),
|
||||
message: t('invoices.confirm_delete'),
|
||||
yesLabel: t('general.ok'),
|
||||
noLabel: t('general.cancel'),
|
||||
variant: 'danger',
|
||||
hideNoButton: false,
|
||||
size: 'lg',
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (res) {
|
||||
await recurringInvoiceStore
|
||||
.deleteMultipleRecurringInvoices(id)
|
||||
.then((res) => {
|
||||
if (res.data.success) {
|
||||
refreshTable()
|
||||
recurringInvoiceStore.$patch((state) => {
|
||||
state.selectedRecurringInvoices = []
|
||||
state.selectAllField = false
|
||||
})
|
||||
notificationStore.showNotification({
|
||||
type: 'success',
|
||||
message: t('recurring_invoices.deleted_message', 2),
|
||||
})
|
||||
} else if (res.data.error) {
|
||||
notificationStore.showNotification({
|
||||
type: 'error',
|
||||
message: res.data.message,
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function toggleFilter() {
|
||||
if (showFilters.value) {
|
||||
clearFilter()
|
||||
}
|
||||
|
||||
showFilters.value = !showFilters.value
|
||||
}
|
||||
|
||||
async function clearStatusSearch(removedOption, id) {
|
||||
filters.status = ''
|
||||
refreshTable()
|
||||
}
|
||||
|
||||
function setActiveTab(val) {
|
||||
switch (val) {
|
||||
case 'ACTIVE':
|
||||
activeTab.value = t('recurring_invoices.active')
|
||||
break
|
||||
case 'ON_HOLD':
|
||||
activeTab.value = t('recurring_invoices.on_hold')
|
||||
break
|
||||
case 'ALL':
|
||||
activeTab.value = t('recurring_invoices.all')
|
||||
break
|
||||
}
|
||||
}
|
||||
</script>
|
||||
76
resources/scripts/admin/views/recurring-invoices/View.vue
Normal file
76
resources/scripts/admin/views/recurring-invoices/View.vue
Normal file
@ -0,0 +1,76 @@
|
||||
<template>
|
||||
<BasePage class="xl:pl-96">
|
||||
<BasePageHeader :title="pageTitle">
|
||||
<template #actions>
|
||||
<RecurringInvoiceIndexDropdown
|
||||
v-if="hasAtleastOneAbility()"
|
||||
:row="recurringInvoiceStore.newRecurringInvoice"
|
||||
/>
|
||||
</template>
|
||||
</BasePageHeader>
|
||||
|
||||
<RecurringInvoiceViewSidebar />
|
||||
|
||||
<RecurringInvoiceInfo />
|
||||
</BasePage>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, inject } from 'vue'
|
||||
import { useRouter, useRoute } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useDialogStore } from '@/scripts/stores/dialog'
|
||||
import { useUserStore } from '@/scripts/admin/stores/user'
|
||||
import { useRecurringInvoiceStore } from '@/scripts/admin/stores/recurring-invoice'
|
||||
import abilities from '@/scripts/admin/stub/abilities'
|
||||
|
||||
import RecurringInvoiceViewSidebar from '@/scripts/admin/views/recurring-invoices/partials/RecurringInvoiceViewSidebar.vue'
|
||||
import RecurringInvoiceInfo from '@/scripts/admin/views/recurring-invoices/partials/RecurringInvoiceInfo.vue'
|
||||
import RecurringInvoiceIndexDropdown from '@/scripts/admin/components/dropdowns/RecurringInvoiceIndexDropdown.vue'
|
||||
|
||||
const dialogStore = useDialogStore()
|
||||
const recurringInvoiceStore = useRecurringInvoiceStore()
|
||||
const userStore = useUserStore()
|
||||
const { t } = useI18n()
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const pageTitle = computed(() => {
|
||||
return recurringInvoiceStore.newRecurringInvoice
|
||||
? recurringInvoiceStore.newRecurringInvoice?.customer?.name
|
||||
: ''
|
||||
})
|
||||
|
||||
function hasAtleastOneAbility() {
|
||||
return userStore.hasAbilities([
|
||||
abilities.DELETE_RECURRING_INVOICE,
|
||||
abilities.EDIT_RECURRING_INVOICE,
|
||||
])
|
||||
}
|
||||
|
||||
function removeRecurringInvoice(id) {
|
||||
dialogStore
|
||||
.openDialog({
|
||||
title: t('general.are_you_sure'),
|
||||
message: t('recurring_invoices.confirm_delete', 1),
|
||||
yesLabel: t('general.ok'),
|
||||
noLabel: t('general.cancel'),
|
||||
variant: 'danger',
|
||||
size: 'lg',
|
||||
hideNoButton: false,
|
||||
})
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
let data = { ids: [id] }
|
||||
let response = recurringInvoiceStore
|
||||
.deleteRecurringInvoice(data)
|
||||
.then((res) => {
|
||||
if (response) {
|
||||
router.push('/admin/recurring-invoices')
|
||||
return true
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
@ -0,0 +1,329 @@
|
||||
<template>
|
||||
<SelectTemplateModal />
|
||||
<ItemModal />
|
||||
<TaxTypeModal />
|
||||
<SalesTax
|
||||
v-if="salesTaxEnabled && !isLoadingContent"
|
||||
:store="recurringInvoiceStore"
|
||||
store-prop="newRecurringInvoice"
|
||||
:is-edit="isEdit"
|
||||
:customer="recurringInvoiceStore.newRecurringInvoice.customer"
|
||||
/>
|
||||
<BasePage class="relative invoice-create-page">
|
||||
<form @submit.prevent="submitForm">
|
||||
<BasePageHeader :title="pageTitle">
|
||||
<BaseBreadcrumb>
|
||||
<BaseBreadcrumbItem
|
||||
:title="$t('general.home')"
|
||||
to="/admin/dashboard"
|
||||
/>
|
||||
<BaseBreadcrumbItem
|
||||
:title="$t('recurring_invoices.title', 2)"
|
||||
to="/admin/recurring-invoices"
|
||||
/>
|
||||
<BaseBreadcrumbItem
|
||||
v-if="$route.name === 'invoices.edit'"
|
||||
:title="$t('recurring_invoices.edit_invoice')"
|
||||
to="#"
|
||||
active
|
||||
/>
|
||||
<BaseBreadcrumbItem
|
||||
v-else
|
||||
:title="pageTitle"
|
||||
to="#"
|
||||
active
|
||||
/>
|
||||
</BaseBreadcrumb>
|
||||
|
||||
<template #actions>
|
||||
<router-link
|
||||
:to="`/invoices/pdf/${recurringInvoiceStore.newRecurringInvoice.unique_hash}`"
|
||||
>
|
||||
<BaseButton
|
||||
v-if="$route.name === 'invoices.edit'"
|
||||
target="_blank"
|
||||
class="mr-3"
|
||||
variant="primary-outline"
|
||||
type="button"
|
||||
>
|
||||
<span class="flex">
|
||||
{{ $t('general.view_pdf') }}
|
||||
</span>
|
||||
</BaseButton>
|
||||
</router-link>
|
||||
|
||||
<BaseButton
|
||||
:loading="isSaving"
|
||||
:disabled="isSaving"
|
||||
variant="primary"
|
||||
type="submit"
|
||||
>
|
||||
<template #left="slotProps">
|
||||
<BaseIcon
|
||||
v-if="!isSaving"
|
||||
name="SaveIcon"
|
||||
:class="slotProps.class"
|
||||
/>
|
||||
</template>
|
||||
{{ $t('recurring_invoices.save_invoice') }}
|
||||
</BaseButton>
|
||||
</template>
|
||||
</BasePageHeader>
|
||||
|
||||
<!-- Select Customer & Basic Fields -->
|
||||
<div class="grid-cols-12 gap-8 mt-6 mb-8 lg:grid">
|
||||
<InvoiceBasicFields
|
||||
:v="v$"
|
||||
:is-loading="isLoadingContent"
|
||||
:is-edit="isEdit"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<BaseScrollPane>
|
||||
<!-- Invoice Items -->
|
||||
<CreateItems
|
||||
:currency="recurringInvoiceStore.newRecurringInvoice.currency"
|
||||
:is-loading="isLoadingContent"
|
||||
:item-validation-scope="recurringInvoiceValidationScope"
|
||||
:store="recurringInvoiceStore"
|
||||
store-prop="newRecurringInvoice"
|
||||
/>
|
||||
|
||||
<!-- Invoice Templates -->
|
||||
<div
|
||||
class="
|
||||
block
|
||||
mt-10
|
||||
invoice-foot
|
||||
lg:flex lg:justify-between lg:items-start
|
||||
"
|
||||
>
|
||||
<div class="w-full relative lg:w-1/2">
|
||||
<!-- Invoice Custom Notes -->
|
||||
<NoteFields
|
||||
:store="recurringInvoiceStore"
|
||||
store-prop="newRecurringInvoice"
|
||||
:fields="recurringInvoiceFields"
|
||||
type="Invoice"
|
||||
/>
|
||||
|
||||
<!-- Invoice Custom Fields -->
|
||||
<InvoiceCustomFields
|
||||
type="Invoice"
|
||||
:is-edit="isEdit"
|
||||
:is-loading="isLoadingContent"
|
||||
:store="recurringInvoiceStore"
|
||||
store-prop="newRecurringInvoice"
|
||||
:custom-field-scope="recurringInvoiceValidationScope"
|
||||
class="mb-6"
|
||||
/>
|
||||
|
||||
<!-- Invoice Template Button-->
|
||||
<SelectTemplateButton
|
||||
:store="recurringInvoiceStore"
|
||||
store-prop="newRecurringInvoice"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- Invoice Total Card -->
|
||||
<CreateTotal
|
||||
:currency="recurringInvoiceStore.newRecurringInvoice.currency"
|
||||
:is-loading="isLoadingContent"
|
||||
:store="recurringInvoiceStore"
|
||||
store-prop="newRecurringInvoice"
|
||||
tax-popup-type="invoice"
|
||||
/>
|
||||
</div>
|
||||
</BaseScrollPane>
|
||||
</form>
|
||||
</BasePage>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import CreateItems from '@/scripts/admin/components/estimate-invoice-common/CreateItems.vue'
|
||||
import CreateTotal from '@/scripts/admin/components/estimate-invoice-common/CreateTotal.vue'
|
||||
import SelectTemplateButton from '@/scripts/admin/components/estimate-invoice-common/SelectTemplateButton.vue'
|
||||
import InvoiceBasicFields from './RecurringInvoiceCreateBasicFields.vue'
|
||||
import InvoiceCustomFields from '@/scripts/admin/components/custom-fields/CreateCustomFields.vue'
|
||||
import NoteFields from '@/scripts/admin/components/estimate-invoice-common/CreateNotesField.vue'
|
||||
import SalesTax from '@/scripts/admin/components/estimate-invoice-common/SalesTax.vue'
|
||||
|
||||
import {
|
||||
required,
|
||||
maxLength,
|
||||
numeric,
|
||||
helpers,
|
||||
requiredIf,
|
||||
decimal,
|
||||
} from '@vuelidate/validators'
|
||||
|
||||
import useVuelidate from '@vuelidate/core'
|
||||
import { useCompanyStore } from '@/scripts/admin/stores/company'
|
||||
import { useCustomFieldStore } from '@/scripts/admin/stores/custom-field'
|
||||
import { useRecurringInvoiceStore } from '@/scripts/admin/stores/recurring-invoice'
|
||||
import { useModuleStore } from '@/scripts/admin/stores/module'
|
||||
import SelectTemplateModal from '@/scripts/admin/components/modal-components/SelectTemplateModal.vue'
|
||||
import TaxTypeModal from '@/scripts/admin/components/modal-components/TaxTypeModal.vue'
|
||||
import ItemModal from '@/scripts/admin/components/modal-components/ItemModal.vue'
|
||||
|
||||
const recurringInvoiceStore = useRecurringInvoiceStore()
|
||||
const companyStore = useCompanyStore()
|
||||
const customFieldStore = useCustomFieldStore()
|
||||
const moduleStore = useModuleStore()
|
||||
const recurringInvoiceValidationScope = 'newRecurringInvoice'
|
||||
const { t } = useI18n()
|
||||
let isSaving = ref(false)
|
||||
|
||||
const recurringInvoiceFields = ref([
|
||||
'customer',
|
||||
'company',
|
||||
'customerCustom',
|
||||
'invoice',
|
||||
'invoiceCustom',
|
||||
])
|
||||
|
||||
let route = useRoute()
|
||||
let router = useRouter()
|
||||
|
||||
let isLoadingContent = computed(
|
||||
() =>
|
||||
recurringInvoiceStore.isFetchingInvoice ||
|
||||
recurringInvoiceStore.isFetchingInitialSettings
|
||||
)
|
||||
|
||||
let pageTitle = computed(() =>
|
||||
isEdit.value
|
||||
? t('recurring_invoices.edit_invoice')
|
||||
: t('recurring_invoices.new_invoice')
|
||||
)
|
||||
|
||||
let isEdit = computed(() => route.name === 'recurring-invoices.edit')
|
||||
|
||||
const salesTaxEnabled = computed(() => {
|
||||
return (
|
||||
companyStore.selectedCompanySettings.sales_tax_us_enabled === 'YES' &&
|
||||
moduleStore.salesTaxUSEnabled
|
||||
)
|
||||
})
|
||||
|
||||
const rules = {
|
||||
starts_at: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
status: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
frequency: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
limit_by: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
limit_date: {
|
||||
required: helpers.withMessage(
|
||||
t('validation.required'),
|
||||
requiredIf(function () {
|
||||
return recurringInvoiceStore.newRecurringInvoice.limit_by === 'DATE'
|
||||
})
|
||||
),
|
||||
},
|
||||
limit_count: {
|
||||
required: helpers.withMessage(
|
||||
t('validation.required'),
|
||||
requiredIf(function () {
|
||||
return recurringInvoiceStore.newRecurringInvoice.limit_by === 'COUNT'
|
||||
})
|
||||
),
|
||||
},
|
||||
selectedFrequency: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
customer_id: {
|
||||
required: helpers.withMessage(t('validation.required'), required),
|
||||
},
|
||||
exchange_rate: {
|
||||
required: requiredIf(function () {
|
||||
helpers.withMessage(t('validation.required'), required)
|
||||
return recurringInvoiceStore.showExchangeRate
|
||||
}),
|
||||
decimal: helpers.withMessage(t('validation.valid_exchange_rate'), decimal),
|
||||
},
|
||||
}
|
||||
|
||||
const v$ = useVuelidate(
|
||||
rules,
|
||||
computed(() => recurringInvoiceStore.newRecurringInvoice),
|
||||
{ $scope: recurringInvoiceValidationScope }
|
||||
)
|
||||
|
||||
recurringInvoiceStore.resetCurrentRecurringInvoice()
|
||||
recurringInvoiceStore.fetchRecurringInvoiceInitialSettings(isEdit.value)
|
||||
customFieldStore.resetCustomFields()
|
||||
v$.value.$reset
|
||||
|
||||
watch(
|
||||
() => recurringInvoiceStore.newRecurringInvoice.customer,
|
||||
(newVal) => {
|
||||
if (newVal && newVal.currency) {
|
||||
recurringInvoiceStore.newRecurringInvoice.currency = newVal.currency
|
||||
} else {
|
||||
recurringInvoiceStore.newRecurringInvoice.currency =
|
||||
companyStore.selectedCompanyCurrency
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
async function submitForm() {
|
||||
v$.value.$touch()
|
||||
|
||||
if (v$.value.$invalid) {
|
||||
return false
|
||||
}
|
||||
|
||||
isSaving.value = true
|
||||
|
||||
let data = {
|
||||
...recurringInvoiceStore.newRecurringInvoice,
|
||||
sub_total: recurringInvoiceStore.getSubTotal,
|
||||
total: recurringInvoiceStore.getTotal,
|
||||
tax: recurringInvoiceStore.getTotalTax,
|
||||
}
|
||||
|
||||
if (route.params.id) {
|
||||
recurringInvoiceStore
|
||||
.updateRecurringInvoice(data)
|
||||
.then((res) => {
|
||||
if (res.data.data) {
|
||||
router.push(`/admin/recurring-invoices/${res.data.data.id}/view`)
|
||||
}
|
||||
isSaving.value = false
|
||||
})
|
||||
.catch((err) => {
|
||||
isSaving.value = false
|
||||
})
|
||||
} else {
|
||||
submitCreate(data)
|
||||
}
|
||||
}
|
||||
|
||||
function submitCreate(data) {
|
||||
recurringInvoiceStore
|
||||
.addRecurringInvoice(data)
|
||||
.then((res) => {
|
||||
if (res.data.data) {
|
||||
router.push(`/admin/recurring-invoices/${res.data.data.id}/view`)
|
||||
}
|
||||
isSaving.value = false
|
||||
})
|
||||
.catch((err) => {
|
||||
isSaving.value = false
|
||||
})
|
||||
}
|
||||
|
||||
function checkValid() {
|
||||
return false
|
||||
}
|
||||
</script>
|
||||
@ -0,0 +1,285 @@
|
||||
<template>
|
||||
<div class="col-span-5 pr-0">
|
||||
<BaseCustomerSelectPopup
|
||||
v-model="recurringInvoiceStore.newRecurringInvoice.customer"
|
||||
:valid="v.customer_id"
|
||||
:content-loading="isLoading"
|
||||
type="recurring-invoice"
|
||||
/>
|
||||
|
||||
<div class="flex mt-7">
|
||||
<div class="relative w-20 mt-8">
|
||||
<BaseSwitch
|
||||
v-model="recurringInvoiceStore.newRecurringInvoice.send_automatically"
|
||||
class="absolute -top-4"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="ml-2">
|
||||
<p class="p-0 mb-1 leading-snug text-left text-black">
|
||||
{{ $t('recurring_invoices.send_automatically') }}
|
||||
</p>
|
||||
<p
|
||||
class="p-0 m-0 text-xs leading-tight text-left text-gray-500"
|
||||
style="max-width: 480px"
|
||||
>
|
||||
{{ $t('recurring_invoices.send_automatically_desc') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="
|
||||
grid grid-cols-1
|
||||
col-span-7
|
||||
gap-4
|
||||
mt-8
|
||||
lg:gap-6 lg:mt-0 lg:grid-cols-2
|
||||
"
|
||||
>
|
||||
<BaseInputGroup
|
||||
:label="$t('recurring_invoices.starts_at')"
|
||||
:content-loading="isLoading"
|
||||
required
|
||||
:error="v.starts_at.$error && v.starts_at.$errors[0].$message"
|
||||
>
|
||||
<BaseDatePicker
|
||||
v-model="recurringInvoiceStore.newRecurringInvoice.starts_at"
|
||||
:content-loading="isLoading"
|
||||
:calendar-button="true"
|
||||
calendar-button-icon="calendar"
|
||||
:invalid="v.starts_at.$error"
|
||||
@change="getNextInvoiceDate()"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('recurring_invoices.next_invoice_date')"
|
||||
:content-loading="isLoading"
|
||||
required
|
||||
>
|
||||
<BaseDatePicker
|
||||
v-model="recurringInvoiceStore.newRecurringInvoice.next_invoice_at"
|
||||
:content-loading="isLoading"
|
||||
:calendar-button="true"
|
||||
:disabled="true"
|
||||
:loading="isLoadingNextDate"
|
||||
calendar-button-icon="calendar"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('recurring_invoices.limit_by')"
|
||||
:content-loading="isLoading"
|
||||
class="lg:mt-0"
|
||||
required
|
||||
:error="v.limit_by.$error && v.limit_by.$errors[0].$message"
|
||||
>
|
||||
<BaseMultiselect
|
||||
v-model="recurringInvoiceStore.newRecurringInvoice.limit_by"
|
||||
:content-loading="isLoading"
|
||||
:options="limits"
|
||||
label="label"
|
||||
:invalid="v.limit_by.$error"
|
||||
value-prop="value"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
v-if="hasLimitBy('DATE')"
|
||||
:label="$t('recurring_invoices.limit_date')"
|
||||
:content-loading="isLoading"
|
||||
:required="hasLimitBy('DATE')"
|
||||
:error="v.limit_date.$error && v.limit_date.$errors[0].$message"
|
||||
>
|
||||
<BaseDatePicker
|
||||
v-model="recurringInvoiceStore.newRecurringInvoice.limit_date"
|
||||
:content-loading="isLoading"
|
||||
:invalid="v.limit_date.$error"
|
||||
calendar-button-icon="calendar"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
v-if="hasLimitBy('COUNT')"
|
||||
:label="$t('recurring_invoices.count')"
|
||||
:content-loading="isLoading"
|
||||
:required="hasLimitBy('COUNT')"
|
||||
:error="v.limit_count.$error && v.limit_count.$errors[0].$message"
|
||||
>
|
||||
<BaseInput
|
||||
v-model="recurringInvoiceStore.newRecurringInvoice.limit_count"
|
||||
:content-loading="isLoading"
|
||||
:invalid="v.limit_count.$error"
|
||||
type="number"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('recurring_invoices.status')"
|
||||
required
|
||||
:content-loading="isLoading"
|
||||
:error="v.status.$error && v.status.$errors[0].$message"
|
||||
>
|
||||
<BaseMultiselect
|
||||
v-model="recurringInvoiceStore.newRecurringInvoice.status"
|
||||
:options="getStatusOptions"
|
||||
:content-loading="isLoading"
|
||||
:invalid="v.status.$error"
|
||||
:placeholder="$t('recurring_invoices.select_a_status')"
|
||||
value-prop="value"
|
||||
label="value"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
:label="$t('recurring_invoices.frequency.select_frequency')"
|
||||
required
|
||||
:content-loading="isLoading"
|
||||
:error="
|
||||
v.selectedFrequency.$error && v.selectedFrequency.$errors[0].$message
|
||||
"
|
||||
>
|
||||
<BaseMultiselect
|
||||
v-model="recurringInvoiceStore.newRecurringInvoice.selectedFrequency"
|
||||
:content-loading="isLoading"
|
||||
:options="recurringInvoiceStore.frequencies"
|
||||
label="label"
|
||||
:invalid="v.selectedFrequency.$error"
|
||||
object
|
||||
@change="getNextInvoiceDate"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<BaseInputGroup
|
||||
v-if="isCustomFrequency"
|
||||
:label="$t('recurring_invoices.frequency.title')"
|
||||
:content-loading="isLoading"
|
||||
required
|
||||
:error="v.frequency.$error && v.frequency.$errors[0].$message"
|
||||
>
|
||||
<BaseInput
|
||||
v-model="recurringInvoiceStore.newRecurringInvoice.frequency"
|
||||
:content-loading="isLoading"
|
||||
:disabled="!isCustomFrequency"
|
||||
:invalid="v.frequency.$error"
|
||||
:loading="isLoadingNextDate"
|
||||
@update:modelValue="debounceNextDate"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
|
||||
<ExchangeRateConverter
|
||||
:store="recurringInvoiceStore"
|
||||
store-prop="newRecurringInvoice"
|
||||
:v="v"
|
||||
:is-loading="isLoading"
|
||||
:is-edit="isEdit"
|
||||
:customer-currency="recurringInvoiceStore.newRecurringInvoice.currency_id"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { useGlobalStore } from '@/scripts/admin/stores/global'
|
||||
import { useDebounceFn } from '@vueuse/core'
|
||||
import { useRecurringInvoiceStore } from '@/scripts/admin/stores/recurring-invoice'
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
import ExchangeRateConverter from '@/scripts/admin/components/estimate-invoice-common/ExchangeRateConverter.vue'
|
||||
|
||||
const props = defineProps({
|
||||
v: {
|
||||
type: Object,
|
||||
default: null,
|
||||
},
|
||||
isLoading: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
isEdit: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
})
|
||||
|
||||
const route = useRoute()
|
||||
const recurringInvoiceStore = useRecurringInvoiceStore()
|
||||
const globalStore = useGlobalStore()
|
||||
|
||||
const isLoadingNextDate = ref(false)
|
||||
|
||||
const limits = reactive([
|
||||
{ label: 'None', value: 'NONE' },
|
||||
{ label: 'Date', value: 'DATE' },
|
||||
{ label: 'Count', value: 'COUNT' },
|
||||
])
|
||||
|
||||
const isCustomFrequency = computed(() => {
|
||||
return (
|
||||
recurringInvoiceStore.newRecurringInvoice.selectedFrequency &&
|
||||
recurringInvoiceStore.newRecurringInvoice.selectedFrequency.value ===
|
||||
'CUSTOM'
|
||||
)
|
||||
})
|
||||
|
||||
const getStatusOptions = computed(() => {
|
||||
if (props.isEdit) {
|
||||
return globalStore.config.recurring_invoice_status.update_status
|
||||
}
|
||||
return globalStore.config.recurring_invoice_status.create_status
|
||||
})
|
||||
|
||||
watch(
|
||||
() => recurringInvoiceStore.newRecurringInvoice.selectedFrequency,
|
||||
(newValue) => {
|
||||
if (!recurringInvoiceStore.isFetchingInitialSettings) {
|
||||
if (newValue && newValue.value !== 'CUSTOM') {
|
||||
recurringInvoiceStore.newRecurringInvoice.frequency = newValue.value
|
||||
} else {
|
||||
recurringInvoiceStore.newRecurringInvoice.frequency = null
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
// on create
|
||||
if (!route.params.id) {
|
||||
getNextInvoiceDate()
|
||||
}
|
||||
})
|
||||
|
||||
function hasLimitBy(LimitBy) {
|
||||
return recurringInvoiceStore.newRecurringInvoice.limit_by === LimitBy
|
||||
}
|
||||
|
||||
const debounceNextDate = useDebounceFn(() => {
|
||||
getNextInvoiceDate()
|
||||
}, 500)
|
||||
|
||||
async function getNextInvoiceDate() {
|
||||
const val = recurringInvoiceStore.newRecurringInvoice.frequency
|
||||
|
||||
if (!val) {
|
||||
return
|
||||
}
|
||||
|
||||
isLoadingNextDate.value = true
|
||||
|
||||
let data = {
|
||||
starts_at: recurringInvoiceStore.newRecurringInvoice.starts_at,
|
||||
frequency: val,
|
||||
}
|
||||
|
||||
try {
|
||||
await recurringInvoiceStore.fetchRecurringInvoiceFrequencyDate(data)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
isLoadingNextDate.value = false
|
||||
}
|
||||
|
||||
isLoadingNextDate.value = false
|
||||
}
|
||||
</script>
|
||||
@ -0,0 +1,99 @@
|
||||
<template>
|
||||
<SendInvoiceModal />
|
||||
<div class="relative table-container">
|
||||
<BaseTable
|
||||
ref="table"
|
||||
:data="recurringInvoiceStore.newRecurringInvoice.invoices"
|
||||
:columns="invoiceColumns"
|
||||
:loading="recurringInvoiceStore.isFetchingViewData"
|
||||
:placeholder-count="5"
|
||||
class="mt-5"
|
||||
>
|
||||
<!-- Invoice Number -->
|
||||
<template #cell-invoice_number="{ row }">
|
||||
<router-link
|
||||
:to="{ path: `/admin/invoices/${row.data.id}/view` }"
|
||||
class="font-medium text-primary-500"
|
||||
>
|
||||
{{ row.data.invoice_number }}
|
||||
</router-link>
|
||||
</template>
|
||||
|
||||
<!-- Invoice Due amount -->
|
||||
<template #cell-total="{ row }">
|
||||
<BaseFormatMoney
|
||||
:amount="row.data.due_amount"
|
||||
:currency="row.data.currency"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<!-- Invoice status -->
|
||||
<template #cell-status="{ row }">
|
||||
<BaseInvoiceStatusBadge :status="row.data.status" class="px-3 py-1">
|
||||
{{ row.data.status }}
|
||||
</BaseInvoiceStatusBadge>
|
||||
</template>
|
||||
|
||||
<!-- Actions -->
|
||||
<template v-if="hasAtleastOneAbility()" #cell-actions="{ row }">
|
||||
<InvoiceDropdown :row="row.data" :table="table" />
|
||||
</template>
|
||||
</BaseTable>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref, inject } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useUserStore } from '@/scripts/admin/stores/user'
|
||||
import { useRecurringInvoiceStore } from '@/scripts/admin/stores/recurring-invoice'
|
||||
import abilities from '@/scripts/admin/stub/abilities'
|
||||
import InvoiceDropdown from '@/scripts/admin/components/dropdowns/InvoiceIndexDropdown.vue'
|
||||
|
||||
const recurringInvoiceStore = useRecurringInvoiceStore()
|
||||
|
||||
const table = ref(null)
|
||||
const baseSelect = ref(null)
|
||||
const utils = inject('$utils')
|
||||
const { t } = useI18n()
|
||||
const currency = ref(null)
|
||||
const router = useRouter()
|
||||
const userStore = useUserStore()
|
||||
|
||||
const invoiceColumns = computed(() => {
|
||||
return [
|
||||
{
|
||||
key: 'invoice_date',
|
||||
label: t('invoices.date'),
|
||||
thClass: 'extra',
|
||||
tdClass: 'font-medium text-gray-900',
|
||||
},
|
||||
{ key: 'invoice_number', label: t('invoices.invoice') },
|
||||
{ key: 'customer.name', label: t('invoices.customer') },
|
||||
{ key: 'status', label: t('invoices.status') },
|
||||
{ key: 'total', label: t('invoices.total') },
|
||||
|
||||
{
|
||||
key: 'actions',
|
||||
label: t('invoices.action'),
|
||||
tdClass: 'text-right text-sm font-medium',
|
||||
thClass: 'text-right',
|
||||
sortable: false,
|
||||
},
|
||||
]
|
||||
})
|
||||
|
||||
function hasAtleastOneAbility() {
|
||||
return userStore.hasAbilities([
|
||||
abilities.DELETE_INVOICE,
|
||||
abilities.EDIT_INVOICE,
|
||||
abilities.VIEW_INVOICE,
|
||||
abilities.SEND_INVOICE,
|
||||
])
|
||||
}
|
||||
|
||||
function refreshTable() {
|
||||
table.value && table.value.refresh()
|
||||
}
|
||||
</script>
|
||||
@ -0,0 +1,94 @@
|
||||
<template>
|
||||
<BaseCard class="mt-10">
|
||||
<BaseHeading>
|
||||
{{ $t('customers.basic_info') }}
|
||||
</BaseHeading>
|
||||
|
||||
<BaseDescriptionList class="mt-5">
|
||||
<BaseDescriptionListItem
|
||||
:label="$t('recurring_invoices.starts_at')"
|
||||
:content-loading="isLoading"
|
||||
:value="recurringInvoiceStore.newRecurringInvoice?.formatted_starts_at"
|
||||
/>
|
||||
|
||||
<BaseDescriptionListItem
|
||||
:label="$t('recurring_invoices.next_invoice_date')"
|
||||
:content-loading="isLoading"
|
||||
:value="
|
||||
recurringInvoiceStore.newRecurringInvoice?.formatted_next_invoice_at
|
||||
"
|
||||
/>
|
||||
|
||||
<BaseDescriptionListItem
|
||||
v-if="
|
||||
recurringInvoiceStore.newRecurringInvoice?.limit_date &&
|
||||
recurringInvoiceStore.newRecurringInvoice?.limit_by !== 'NONE'
|
||||
"
|
||||
:label="$t('recurring_invoices.limit_date')"
|
||||
:content-loading="isLoading"
|
||||
:value="recurringInvoiceStore.newRecurringInvoice?.limit_date"
|
||||
/>
|
||||
|
||||
<BaseDescriptionListItem
|
||||
v-if="
|
||||
recurringInvoiceStore.newRecurringInvoice?.limit_date &&
|
||||
recurringInvoiceStore.newRecurringInvoice?.limit_by !== 'NONE'
|
||||
"
|
||||
:label="$t('recurring_invoices.limit_by')"
|
||||
:content-loading="isLoading"
|
||||
:value="recurringInvoiceStore.newRecurringInvoice?.limit_by"
|
||||
/>
|
||||
|
||||
<BaseDescriptionListItem
|
||||
v-if="recurringInvoiceStore.newRecurringInvoice?.limit_count"
|
||||
:label="$t('recurring_invoices.limit_count')"
|
||||
:value="recurringInvoiceStore.newRecurringInvoice?.limit_count"
|
||||
:content-loading="isLoading"
|
||||
/>
|
||||
|
||||
<BaseDescriptionListItem
|
||||
v-if="recurringInvoiceStore.newRecurringInvoice?.selectedFrequency"
|
||||
:label="$t('recurring_invoices.frequency.title')"
|
||||
:value="
|
||||
recurringInvoiceStore.newRecurringInvoice?.selectedFrequency?.label
|
||||
"
|
||||
:content-loading="isLoading"
|
||||
/>
|
||||
</BaseDescriptionList>
|
||||
|
||||
<BaseHeading class="mt-8">
|
||||
{{ $t('invoices.title', 2) }}
|
||||
</BaseHeading>
|
||||
|
||||
<Invoices />
|
||||
</BaseCard>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed, watch, reactive, inject } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useRecurringInvoiceStore } from '@/scripts/admin/stores/recurring-invoice'
|
||||
import Invoices from './Invoices.vue'
|
||||
|
||||
const recurringInvoiceStore = useRecurringInvoiceStore()
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
let isLoading = computed(() => {
|
||||
return recurringInvoiceStore.isFetchingViewData
|
||||
})
|
||||
|
||||
watch(
|
||||
route,
|
||||
() => {
|
||||
if (route.params.id && route.name === 'recurring-invoices.view') {
|
||||
loadRecurringInvoice()
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
|
||||
async function loadRecurringInvoice() {
|
||||
await recurringInvoiceStore.fetchRecurringInvoice(route.params.id)
|
||||
}
|
||||
</script>
|
||||
@ -0,0 +1,322 @@
|
||||
<script setup>
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { computed, reactive, ref, watch, inject } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { debounce } from 'lodash'
|
||||
import { useRecurringInvoiceStore } from '@/scripts/admin/stores/recurring-invoice'
|
||||
import { useModalStore } from '@/scripts/stores/modal'
|
||||
import { useNotificationStore } from '@/scripts/stores/notification'
|
||||
import { useUserStore } from '@/scripts/admin/stores/user'
|
||||
import { useDialogStore } from '@/scripts/stores/dialog'
|
||||
import LoadingIcon from '@/scripts/components/icons/LoadingIcon.vue'
|
||||
|
||||
const modalStore = useModalStore()
|
||||
const recurringInvoiceStore = useRecurringInvoiceStore()
|
||||
const notificationStore = useNotificationStore()
|
||||
const userStore = useUserStore()
|
||||
const dialogStore = useDialogStore()
|
||||
|
||||
const { t } = useI18n()
|
||||
const id = ref(null)
|
||||
const count = ref(null)
|
||||
const currency = ref(null)
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const status = ref([
|
||||
'DRAFT',
|
||||
'SENT',
|
||||
'VIEWED',
|
||||
'EXPIRED',
|
||||
'ACCEPTED',
|
||||
'REJECTED',
|
||||
])
|
||||
const isSearching = ref(false)
|
||||
const isLoading = ref(false)
|
||||
|
||||
const searchData = reactive({
|
||||
orderBy: null,
|
||||
orderByField: null,
|
||||
searchText: null,
|
||||
})
|
||||
|
||||
const getOrderBy = computed(() => {
|
||||
if (searchData.orderBy === 'asc' || searchData.orderBy == null) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
})
|
||||
|
||||
function hasActiveUrl(id) {
|
||||
return route.params.id == id
|
||||
}
|
||||
|
||||
async function loadRecurringInvoices() {
|
||||
isLoading.value = true
|
||||
await recurringInvoiceStore.fetchRecurringInvoices()
|
||||
isLoading.value = false
|
||||
|
||||
setTimeout(() => {
|
||||
scrollToRecurringInvoice()
|
||||
}, 500)
|
||||
}
|
||||
|
||||
function scrollToRecurringInvoice() {
|
||||
const el = document.getElementById(`recurring-invoice-${route.params.id}`)
|
||||
if (el) {
|
||||
el.scrollIntoView({ behavior: 'smooth' })
|
||||
el.classList.add('shake')
|
||||
}
|
||||
}
|
||||
|
||||
async function onSearched() {
|
||||
let data = ''
|
||||
if (
|
||||
searchData.searchText !== '' &&
|
||||
searchData.searchText !== null &&
|
||||
searchData.searchText !== undefined
|
||||
) {
|
||||
data += `search=${searchData.searchText}&`
|
||||
}
|
||||
|
||||
if (searchData.orderBy !== null && searchData.orderBy !== undefined) {
|
||||
data += `orderBy=${searchData.orderBy}&`
|
||||
}
|
||||
if (
|
||||
searchData.orderByField !== null &&
|
||||
searchData.orderByField !== undefined
|
||||
) {
|
||||
data += `orderByField=${searchData.orderByField}`
|
||||
}
|
||||
isSearching.value = true
|
||||
let response = await recurringInvoiceStore.searchRecurringInvoice(data)
|
||||
isSearching.value = false
|
||||
if (response.data) {
|
||||
recurringInvoiceStore.recurringInvoices = response.data.data
|
||||
}
|
||||
}
|
||||
|
||||
function sortData() {
|
||||
if (searchData.orderBy === 'asc') {
|
||||
searchData.orderBy = 'desc'
|
||||
onSearched()
|
||||
return true
|
||||
}
|
||||
searchData.orderBy = 'asc'
|
||||
onSearched()
|
||||
return true
|
||||
}
|
||||
|
||||
loadRecurringInvoices()
|
||||
onSearched = debounce(onSearched, 500)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<!-- sidebar -->
|
||||
<div
|
||||
class="
|
||||
fixed
|
||||
top-0
|
||||
left-0
|
||||
hidden
|
||||
h-full
|
||||
pt-16
|
||||
pb-4
|
||||
ml-56
|
||||
bg-white
|
||||
xl:ml-64
|
||||
w-88
|
||||
xl:block
|
||||
"
|
||||
>
|
||||
<div
|
||||
class="
|
||||
flex
|
||||
items-center
|
||||
justify-between
|
||||
px-4
|
||||
pt-8
|
||||
pb-2
|
||||
border border-gray-200 border-solid
|
||||
height-full
|
||||
"
|
||||
>
|
||||
<div class="mb-6">
|
||||
<BaseInput
|
||||
v-model="searchData.searchText"
|
||||
:placeholder="$t('general.search')"
|
||||
type="text"
|
||||
variant="gray"
|
||||
@input="onSearched()"
|
||||
>
|
||||
<template #right>
|
||||
<BaseIcon name="SearchIcon" class="h-5 text-gray-400" />
|
||||
</template>
|
||||
</BaseInput>
|
||||
</div>
|
||||
|
||||
<div class="flex mb-6 ml-3" role="group" aria-label="First group">
|
||||
<BaseDropdown class="ml-3" position="bottom-start">
|
||||
<template #activator>
|
||||
<BaseButton size="md" variant="gray">
|
||||
<BaseIcon name="FilterIcon" class="h-5" />
|
||||
</BaseButton>
|
||||
</template>
|
||||
<div
|
||||
class="
|
||||
px-2
|
||||
py-1
|
||||
pb-2
|
||||
mb-1 mb-2
|
||||
text-sm
|
||||
border-b border-gray-200 border-solid
|
||||
"
|
||||
>
|
||||
{{ $t('general.sort_by') }}
|
||||
</div>
|
||||
|
||||
<BaseDropdownItem class="flex px-1 py-2 cursor-pointer">
|
||||
<BaseInputGroup class="-mt-3 font-normal">
|
||||
<BaseRadio
|
||||
id="filter_next_invoice_date"
|
||||
v-model="searchData.orderByField"
|
||||
:label="$t('recurring_invoices.next_invoice_date')"
|
||||
size="sm"
|
||||
name="filter"
|
||||
value="next_invoice_at"
|
||||
@update:modelValue="onSearched"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
</BaseDropdownItem>
|
||||
|
||||
<BaseDropdownItem class="flex px-1 py-2 cursor-pointer">
|
||||
<BaseInputGroup class="-mt-3 font-normal">
|
||||
<BaseRadio
|
||||
id="filter_start_date"
|
||||
v-model="searchData.orderByField"
|
||||
:label="$t('recurring_invoices.starts_at')"
|
||||
value="starts_at"
|
||||
size="sm"
|
||||
name="filter"
|
||||
@update:modelValue="onSearched"
|
||||
/>
|
||||
</BaseInputGroup>
|
||||
</BaseDropdownItem>
|
||||
</BaseDropdown>
|
||||
|
||||
<BaseButton class="ml-1" size="md" variant="gray" @click="sortData">
|
||||
<BaseIcon v-if="getOrderBy" name="SortAscendingIcon" class="h-5" />
|
||||
<BaseIcon v-else name="SortDescendingIcon" class="h-5" />
|
||||
</BaseButton>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="recurringInvoiceStore && recurringInvoiceStore.recurringInvoices"
|
||||
class="
|
||||
h-full
|
||||
pb-32
|
||||
overflow-y-scroll
|
||||
border-l border-gray-200 border-solid
|
||||
base-scroll
|
||||
"
|
||||
>
|
||||
<div
|
||||
v-for="(invoice, index) in recurringInvoiceStore.recurringInvoices"
|
||||
:key="index"
|
||||
>
|
||||
<router-link
|
||||
v-if="invoice && !isLoading"
|
||||
:id="'recurring-invoice-' + invoice.id"
|
||||
:to="`/admin/recurring-invoices/${invoice.id}/view`"
|
||||
:class="[
|
||||
'flex justify-between side-invoice p-4 cursor-pointer hover:bg-gray-100 items-center border-l-4 border-transparent',
|
||||
{
|
||||
'bg-gray-100 border-l-4 border-primary-500 border-solid':
|
||||
hasActiveUrl(invoice.id),
|
||||
},
|
||||
]"
|
||||
style="border-bottom: 1px solid rgba(185, 193, 209, 0.41)"
|
||||
>
|
||||
<div class="flex-2">
|
||||
<BaseText
|
||||
:text="invoice.customer.name"
|
||||
:length="30"
|
||||
class="
|
||||
pr-2
|
||||
mb-2
|
||||
text-sm
|
||||
not-italic
|
||||
font-normal
|
||||
leading-5
|
||||
text-black
|
||||
capitalize
|
||||
truncate
|
||||
"
|
||||
/>
|
||||
|
||||
<div
|
||||
class="
|
||||
mt-1
|
||||
mb-2
|
||||
text-xs
|
||||
not-italic
|
||||
font-medium
|
||||
leading-5
|
||||
text-gray-600
|
||||
"
|
||||
>
|
||||
{{ invoice.invoice_number }}
|
||||
</div>
|
||||
<BaseRecurringInvoiceStatusBadge
|
||||
:status="invoice.status"
|
||||
class="px-1 text-xs"
|
||||
>
|
||||
{{ invoice.status }}
|
||||
</BaseRecurringInvoiceStatusBadge>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 whitespace-nowrap right">
|
||||
<BaseFormatMoney
|
||||
class="
|
||||
block
|
||||
mb-2
|
||||
text-xl
|
||||
not-italic
|
||||
font-semibold
|
||||
leading-8
|
||||
text-right text-gray-900
|
||||
"
|
||||
:amount="invoice.total"
|
||||
:currency="invoice.customer.currency"
|
||||
/>
|
||||
|
||||
<div
|
||||
class="
|
||||
text-sm
|
||||
not-italic
|
||||
font-normal
|
||||
leading-5
|
||||
text-right text-gray-600
|
||||
est-date
|
||||
"
|
||||
>
|
||||
{{ invoice.formatted_starts_at }}
|
||||
</div>
|
||||
</div>
|
||||
</router-link>
|
||||
</div>
|
||||
<div class="flex justify-center p-4 items-center">
|
||||
<LoadingIcon
|
||||
v-if="isLoading"
|
||||
class="h-6 m-1 animate-spin text-primary-400"
|
||||
/>
|
||||
</div>
|
||||
<p
|
||||
v-if="!recurringInvoiceStore.recurringInvoices.length && !isLoading"
|
||||
class="flex justify-center px-4 mt-5 text-sm text-gray-600"
|
||||
>
|
||||
{{ $t('invoices.no_matching_invoices') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user