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,527 @@
<template>
<PaymentModeModal />
<BasePage class="relative payment-create">
<form action="" @submit.prevent="submitPaymentData">
<BasePageHeader :title="pageTitle" class="mb-5">
<BaseBreadcrumb>
<BaseBreadcrumbItem
:title="$t('general.home')"
to="/admin/dashboard"
/>
<BaseBreadcrumbItem
:title="$tc('payments.payment', 2)"
to="/admin/payments"
/>
<BaseBreadcrumbItem :title="pageTitle" to="#" active />
</BaseBreadcrumb>
<template #actions>
<BaseButton
:loading="isSaving"
:disabled="isSaving"
variant="primary"
type="submit"
class="hidden sm:flex"
>
<template #left="slotProps">
<BaseIcon
v-if="!isSaving"
name="SaveIcon"
:class="slotProps.class"
/>
</template>
{{
isEdit
? $t('payments.update_payment')
: $t('payments.save_payment')
}}
</BaseButton>
</template>
</BasePageHeader>
<BaseCard>
<BaseInputGrid>
<BaseInputGroup
:label="$t('payments.date')"
:content-loading="isLoadingContent"
required
:error="
v$.currentPayment.payment_date.$error &&
v$.currentPayment.payment_date.$errors[0].$message
"
>
<BaseDatePicker
v-model="paymentStore.currentPayment.payment_date"
:content-loading="isLoadingContent"
:calendar-button="true"
calendar-button-icon="calendar"
:invalid="v$.currentPayment.payment_date.$error"
@update:modelValue="v$.currentPayment.payment_date.$touch()"
/>
</BaseInputGroup>
<BaseInputGroup
:label="$t('payments.payment_number')"
:content-loading="isLoadingContent"
required
>
<BaseInput
v-model="paymentStore.currentPayment.payment_number"
:content-loading="isLoadingContent"
/>
</BaseInputGroup>
<BaseInputGroup
:label="$t('payments.customer')"
:error="
v$.currentPayment.customer_id.$error &&
v$.currentPayment.customer_id.$errors[0].$message
"
:content-loading="isLoadingContent"
required
>
<BaseCustomerSelectInput
v-model="paymentStore.currentPayment.customer_id"
:content-loading="isLoadingContent"
:invalid="v$.currentPayment.customer_id.$error"
:placeholder="$t('customers.select_a_customer')"
:fetch-all="isEdit"
show-action
@update:modelValue="
selectNewCustomer(paymentStore.currentPayment.customer_id)
"
/>
</BaseInputGroup>
<BaseInputGroup
:content-loading="isLoadingContent"
:label="$t('payments.invoice')"
:help-text="
selectedInvoice
? `Due Amount: ${
paymentStore.currentPayment.maxPayableAmount / 100
}`
: ''
"
>
<BaseMultiselect
v-model="paymentStore.currentPayment.invoice_id"
:content-loading="isLoadingContent"
value-prop="id"
track-by="invoice_number"
label="invoice_number"
:options="invoiceList"
:loading="isLoadingInvoices"
:placeholder="$t('invoices.select_invoice')"
@select="onSelectInvoice"
>
<template #singlelabel="{ value }">
<div class="absolute left-3.5">
{{ value.invoice_number }} ({{
utils.formatMoney(value.total, value.customer.currency)
}})
</div>
</template>
<template #option="{ option }">
{{ option.invoice_number }} ({{
utils.formatMoney(option.total, option.customer.currency)
}})
</template>
</BaseMultiselect>
</BaseInputGroup>
<BaseInputGroup
:label="$t('payments.amount')"
:content-loading="isLoadingContent"
:error="
v$.currentPayment.amount.$error &&
v$.currentPayment.amount.$errors[0].$message
"
required
>
<div class="relative w-full">
<BaseMoney
:key="paymentStore.currentPayment.currency"
v-model="amount"
:currency="paymentStore.currentPayment.currency"
:content-loading="isLoadingContent"
:invalid="v$.currentPayment.amount.$error"
@update:modelValue="v$.currentPayment.amount.$touch()"
/>
</div>
</BaseInputGroup>
<BaseInputGroup
:content-loading="isLoadingContent"
:label="$t('payments.payment_mode')"
>
<BaseMultiselect
v-model="paymentStore.currentPayment.payment_method_id"
:content-loading="isLoadingContent"
label="name"
value-prop="id"
track-by="name"
:options="paymentStore.paymentModes"
:placeholder="$t('payments.select_payment_mode')"
searchable
>
<template #action>
<BaseSelectAction @click="addPaymentMode">
<BaseIcon
name="PlusIcon"
class="h-4 mr-2 -ml-2 text-center text-primary-400"
/>
{{ $t('settings.payment_modes.add_payment_mode') }}
</BaseSelectAction>
</template>
</BaseMultiselect>
</BaseInputGroup>
<ExchangeRateConverter
:store="paymentStore"
store-prop="currentPayment"
:v="v$.currentPayment"
:is-loading="isLoadingContent"
:is-edit="isEdit"
:customer-currency="paymentStore.currentPayment.currency_id"
/>
</BaseInputGrid>
<!-- Payment Custom Fields -->
<PaymentCustomFields
type="Payment"
:is-edit="isEdit"
:is-loading="isLoadingContent"
:store="paymentStore"
store-prop="currentPayment"
:custom-field-scope="paymentValidationScope"
class="mt-6"
/>
<!-- Payment Note field -->
<div class="relative mt-6">
<div
class="
z-20
float-right
text-sm
font-semibold
leading-5
text-primary-400
"
>
<SelectNotePopup type="Payment" @select="onSelectNote" />
</div>
<label class="mb-4 text-sm font-medium text-gray-800">
{{ $t('estimates.notes') }}
</label>
<BaseCustomInput
v-model="paymentStore.currentPayment.notes"
:content-loading="isLoadingContent"
:fields="PaymentFields"
class="mt-1"
/>
</div>
<BaseButton
:loading="isSaving"
:content-loading="isLoadingContent"
variant="primary"
type="submit"
class="flex justify-center w-full mt-4 sm:hidden md:hidden"
>
<template #left="slotProps">
<BaseIcon
v-if="!isSaving"
name="SaveIcon"
:class="slotProps.class"
/>
</template>
{{
isEdit ? $t('payments.update_payment') : $t('payments.save_payment')
}}
</BaseButton>
</BaseCard>
</form>
</BasePage>
</template>
<script setup>
import ExchangeRateConverter from '@/scripts/admin/components/estimate-invoice-common/ExchangeRateConverter.vue'
import {
ref,
reactive,
computed,
inject,
watchEffect,
onBeforeUnmount,
} from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
import {
required,
numeric,
helpers,
between,
requiredIf,
decimal,
} from '@vuelidate/validators'
import useVuelidate from '@vuelidate/core'
import { useCustomerStore } from '@/scripts/admin/stores/customer'
import { usePaymentStore } from '@/scripts/admin/stores/payment'
import { useNotificationStore } from '@/scripts/stores/notification'
import { useCustomFieldStore } from '@/scripts/admin/stores/custom-field'
import { useCompanyStore } from '@/scripts/admin/stores/company'
import { useModalStore } from '@/scripts/stores/modal'
import { useInvoiceStore } from '@/scripts/admin/stores/invoice'
import { useGlobalStore } from '@/scripts/admin/stores/global'
import SelectNotePopup from '@/scripts/admin/components/SelectNotePopup.vue'
import PaymentCustomFields from '@/scripts/admin/components/custom-fields/CreateCustomFields.vue'
import PaymentModeModal from '@/scripts/admin/components/modal-components/PaymentModeModal.vue'
const route = useRoute()
const router = useRouter()
const paymentStore = usePaymentStore()
const notificationStore = useNotificationStore()
const customerStore = useCustomerStore()
const customFieldStore = useCustomFieldStore()
const companyStore = useCompanyStore()
const modalStore = useModalStore()
const invoiceStore = useInvoiceStore()
const globalStore = useGlobalStore()
const utils = inject('utils')
const { t } = useI18n()
let isSaving = ref(false)
let isLoadingInvoices = ref(false)
let invoiceList = ref([])
const selectedInvoice = ref(null)
const paymentValidationScope = 'newEstimate'
const PaymentFields = reactive([
'customer',
'company',
'customerCustom',
'payment',
'paymentCustom',
])
const amount = computed({
get: () => paymentStore.currentPayment.amount / 100,
set: (value) => {
paymentStore.currentPayment.amount = Math.round(value * 100)
},
})
const isLoadingContent = computed(() => paymentStore.isFetchingInitialData)
const isEdit = computed(() => route.name === 'payments.edit')
const pageTitle = computed(() => {
if (isEdit.value) {
return t('payments.edit_payment')
}
return t('payments.new_payment')
})
const rules = computed(() => {
return {
currentPayment: {
customer_id: {
required: helpers.withMessage(t('validation.required'), required),
},
payment_date: {
required: helpers.withMessage(t('validation.required'), required),
},
amount: {
required: helpers.withMessage(t('validation.required'), required),
between: helpers.withMessage(
t('validation.payment_greater_than_due_amount'),
between(0, paymentStore.currentPayment.maxPayableAmount)
),
},
exchange_rate: {
required: requiredIf(function () {
helpers.withMessage(t('validation.required'), required)
return paymentStore.showExchangeRate
}),
decimal: helpers.withMessage(
t('validation.valid_exchange_rate'),
decimal
),
},
},
}
})
const v$ = useVuelidate(rules, paymentStore, {
$scope: paymentValidationScope,
})
watchEffect(() => {
// fetch customer and its invoices
paymentStore.currentPayment.customer_id
? onCustomerChange(paymentStore.currentPayment.customer_id)
: ''
if (route.query.customer) {
paymentStore.currentPayment.customer_id = route.query.customer
}
})
// Reset State on Create
paymentStore.resetCurrentPayment()
if (route.query.customer) {
paymentStore.currentPayment.customer_id = route.query.customer
}
paymentStore.fetchPaymentInitialData(isEdit.value)
if (route.params.id && !isEdit.value) {
setInvoiceFromUrl()
}
async function addPaymentMode() {
modalStore.openModal({
title: t('settings.payment_modes.add_payment_mode'),
componentName: 'PaymentModeModal',
})
}
function onSelectNote(data) {
paymentStore.currentPayment.notes = '' + data.notes
}
async function setInvoiceFromUrl() {
let res = await invoiceStore.fetchInvoice(route?.params?.id)
paymentStore.currentPayment.customer_id = res.data.data.customer.id
paymentStore.currentPayment.invoice_id = res.data.data.id
}
async function onSelectInvoice(id) {
if (id) {
selectedInvoice.value = invoiceList.value.find((inv) => inv.id === id)
amount.value = selectedInvoice.value.due_amount / 100
paymentStore.currentPayment.maxPayableAmount =
selectedInvoice.value.due_amount
}
}
function onCustomerChange(customer_id) {
if (customer_id) {
let data = {
customer_id: customer_id,
status: 'DUE',
limit: 'all',
}
if (isEdit.value) {
data.status = ''
}
isLoadingInvoices.value = true
Promise.all([
invoiceStore.fetchInvoices(data),
customerStore.fetchCustomer(customer_id),
])
.then(async ([res1, res2]) => {
if (res1) {
invoiceList.value = [...res1.data.data]
}
if (res2 && res2.data) {
paymentStore.currentPayment.selectedCustomer = res2.data.data
paymentStore.currentPayment.customer = res2.data.data
paymentStore.currentPayment.currency = res2.data.data.currency
}
if (paymentStore.currentPayment.invoice_id) {
selectedInvoice.value = invoiceList.value.find(
(inv) => inv.id === paymentStore.currentPayment.invoice_id
)
paymentStore.currentPayment.maxPayableAmount =
selectedInvoice.value.due_amount +
paymentStore.currentPayment.amount
if (amount.value === 0) {
amount.value = selectedInvoice.value.due_amount / 100
}
}
if (isEdit.value) {
// remove all invoices that are paid except currently selected invoice
invoiceList.value = invoiceList.value.filter((v) => {
return (
v.due_amount > 0 || v.id == paymentStore.currentPayment.invoice_id
)
})
}
isLoadingInvoices.value = false
})
.catch((error) => {
isLoadingInvoices.value = false
console.error(error, 'error')
})
}
}
onBeforeUnmount(() => {
paymentStore.resetCurrentPayment()
invoiceList.value = []
})
async function submitPaymentData() {
v$.value.$touch()
if (v$.value.$invalid) {
return false
}
isSaving.value = true
let data = {
...paymentStore.currentPayment,
}
let response = null
try {
const action = isEdit.value
? paymentStore.updatePayment
: paymentStore.addPayment
response = await action(data)
router.push(`/admin/payments/${response.data.data.id}/view`)
} catch (err) {
isSaving.value = false
}
}
function selectNewCustomer(id) {
let params = {
userId: id,
}
if (route.params.id) params.model_id = route.params.id
paymentStore.currentPayment.invoice_id = selectedInvoice.value = null
paymentStore.currentPayment.amount = 0
invoiceList.value = []
paymentStore.getNextNumber(params, true)
}
</script>

View File

@ -0,0 +1,380 @@
<template>
<BasePage class="payments">
<SendPaymentModal />
<BasePageHeader :title="$t('payments.title')">
<BaseBreadcrumb>
<BaseBreadcrumbItem :title="$t('general.home')" to="dashboard" />
<BaseBreadcrumbItem :title="$tc('payments.payment', 2)" to="#" active />
</BaseBreadcrumb>
<template #actions>
<BaseButton
v-show="paymentStore.paymentTotalCount"
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_PAYMENT)"
variant="primary"
class="ml-4"
@click="$router.push('/admin/payments/create')"
>
<template #left="slotProps">
<BaseIcon name="PlusIcon" :class="slotProps.class" />
</template>
{{ $t('payments.add_payment') }}
</BaseButton>
</template>
</BasePageHeader>
<BaseFilterWrapper :show="showFilters" class="mt-3" @clear="clearFilter">
<BaseInputGroup :label="$t('payments.customer')">
<BaseCustomerSelectInput
v-model="filters.customer_id"
:placeholder="$t('customers.type_or_click')"
value-prop="id"
label="name"
/>
</BaseInputGroup>
<BaseInputGroup :label="$t('payments.payment_number')">
<BaseInput v-model="filters.payment_number">
<template #left="slotProps">
<BaseIcon name="HashtagIcon" :class="slotProps.class" />
</template>
</BaseInput>
</BaseInputGroup>
<BaseInputGroup :label="$t('payments.payment_mode')">
<BaseMultiselect
v-model="filters.payment_mode"
value-prop="id"
track-by="name"
:filter-results="false"
label="name"
resolve-on-load
:delay="500"
searchable
:options="searchPayment"
/>
</BaseInputGroup>
</BaseFilterWrapper>
<BaseEmptyPlaceholder
v-if="showEmptyScreen"
:title="$t('payments.no_payments')"
:description="$t('payments.list_of_payments')"
>
<CapsuleIcon class="mt-5 mb-4" />
<template
v-if="userStore.hasAbilities(abilities.CREATE_PAYMENT)"
#actions
>
<BaseButton
variant="primary-outline"
@click="$router.push('/admin/payments/create')"
>
<template #left="slotProps">
<BaseIcon name="PlusIcon" :class="slotProps.class" />
</template>
{{ $t('payments.add_new_payment') }}
</BaseButton>
</template>
</BaseEmptyPlaceholder>
<div v-show="!showEmptyScreen" class="relative table-container">
<!-- Multiple Select Actions -->
<div class="relative flex items-center justify-end h-5">
<BaseDropdown v-if="paymentStore.selectedPayments.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="removeMultiplePayments">
<BaseIcon name="TrashIcon" class="mr-3 text-gray-600" />
{{ $t('general.delete') }}
</BaseDropdownItem>
</BaseDropdown>
</div>
<BaseTable
ref="tableComponent"
:data="fetchData"
:columns="paymentColumns"
:placeholder-count="paymentStore.paymentTotalCount >= 20 ? 10 : 5"
class="mt-3"
>
<!-- Select All Checkbox -->
<template #header>
<div class="absolute items-center left-6 top-2.5 select-none">
<BaseCheckbox
v-model="selectAllFieldStatus"
variant="primary"
@change="paymentStore.selectAllPayments"
/>
</div>
</template>
<template #cell-status="{ row }">
<div class="relative block">
<BaseCheckbox
:id="row.id"
v-model="selectField"
:value="row.data.id"
variant="primary"
/>
</div>
</template>
<template #cell-payment_date="{ row }">
{{ row.data.formatted_payment_date }}
</template>
<template #cell-payment_number="{ row }">
<router-link
:to="{ path: `payments/${row.data.id}/view` }"
class="font-medium text-primary-500"
>
{{ row.data.payment_number }}
</router-link>
</template>
<template #cell-name="{ row }">
<BaseText :text="row.data.customer.name" :length="30" tag="span" />
</template>
<template #cell-payment_mode="{ row }">
<span>
{{ row.data.payment_method ? row.data.payment_method.name : '-' }}
</span>
</template>
<template #cell-invoice_number="{ row }">
<span>
{{
row?.data?.invoice?.invoice_number
? row?.data?.invoice?.invoice_number
: '-'
}}
</span>
</template>
<template #cell-amount="{ row }">
<BaseFormatMoney
:amount="row.data.amount"
:currency="row.data.customer.currency"
/>
</template>
<template v-if="hasAtleastOneAbility()" #cell-actions="{ row }">
<PaymentDropdown :row="row.data" :table="tableComponent" />
</template>
</BaseTable>
</div>
</BasePage>
</template>
<script setup>
import { debouncedWatch } from '@vueuse/core'
import { ref, reactive, computed, onUnmounted } from 'vue'
import { useI18n } from 'vue-i18n'
import { useDialogStore } from '@/scripts/stores/dialog'
import { usePaymentStore } from '@/scripts/admin/stores/payment'
import { useCompanyStore } from '@/scripts/admin/stores/company'
import { useUserStore } from '@/scripts/admin/stores/user'
import abilities from '@/scripts/admin/stub/abilities'
import CapsuleIcon from '@/scripts/components/icons/empty/CapsuleIcon.vue'
import PaymentDropdown from '@/scripts/admin/components/dropdowns/PaymentIndexDropdown.vue'
import SendPaymentModal from '@/scripts/admin/components/modal-components/SendPaymentModal.vue'
const { t } = useI18n()
let showFilters = ref(false)
let isFetchingInitialData = ref(true)
let tableComponent = ref(null)
const filters = reactive({
customer: '',
payment_mode: '',
payment_number: '',
})
const paymentStore = usePaymentStore()
const companyStore = useCompanyStore()
const dialogStore = useDialogStore()
const userStore = useUserStore()
const showEmptyScreen = computed(() => {
return !paymentStore.paymentTotalCount && !isFetchingInitialData.value
})
const paymentColumns = computed(() => {
return [
{
key: 'status',
sortable: false,
thClass: 'extra w-10',
tdClass: 'text-left text-sm font-medium extra',
},
{
key: 'payment_date',
label: t('payments.date'),
thClass: 'extra',
tdClass: 'font-medium text-gray-900',
},
{ key: 'payment_number', label: t('payments.payment_number') },
{ key: 'name', label: t('payments.customer') },
{ key: 'payment_mode', label: t('payments.payment_mode') },
{ key: 'invoice_number', label: t('invoices.invoice_number') },
{ key: 'amount', label: t('payments.amount') },
{
key: 'actions',
label: '',
tdClass: 'text-right text-sm font-medium',
sortable: false,
},
]
})
const selectField = computed({
get: () => paymentStore.selectedPayments,
set: (value) => {
return paymentStore.selectPayment(value)
},
})
const selectAllFieldStatus = computed({
get: () => paymentStore.selectAllField,
set: (value) => {
return paymentStore.setSelectAllState(value)
},
})
debouncedWatch(
filters,
() => {
setFilters()
},
{ debounce: 500 }
)
onUnmounted(() => {
if (paymentStore.selectAllField) {
paymentStore.selectAllPayments()
}
})
paymentStore.fetchPaymentModes({ limit: 'all' })
async function searchPayment(search) {
let res = await paymentStore.fetchPaymentModes({ search })
return res.data.data
}
function hasAtleastOneAbility() {
return userStore.hasAbilities([
abilities.DELETE_PAYMENT,
abilities.EDIT_PAYMENT,
abilities.VIEW_PAYMENT,
abilities.SEND_PAYMENT,
])
}
async function fetchData({ page, filter, sort }) {
let data = {
customer_id: filters.customer_id,
payment_method_id:
filters.payment_mode !== null ? filters.payment_mode : '',
payment_number: filters.payment_number,
orderByField: sort.fieldName || 'created_at',
orderBy: sort.order || 'desc',
page,
}
isFetchingInitialData.value = true
let response = await paymentStore.fetchPayments(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 refreshTable() {
tableComponent.value && tableComponent.value.refresh()
}
function setFilters() {
refreshTable()
}
function clearFilter() {
filters.customer_id = ''
filters.payment_mode = ''
filters.payment_number = ''
}
function toggleFilter() {
if (showFilters.value) {
clearFilter()
}
showFilters.value = !showFilters.value
}
function removeMultiplePayments() {
dialogStore
.openDialog({
title: t('general.are_you_sure'),
message: t('payments.confirm_delete', 2),
yesLabel: t('general.ok'),
noLabel: t('general.cancel'),
variant: 'danger',
hideNoButton: false,
size: 'lg',
})
.then((res) => {
if (res) {
paymentStore.deleteMultiplePayments().then((response) => {
if (response.data.success) {
refreshTable()
}
})
}
})
}
</script>

View File

@ -0,0 +1,436 @@
<template>
<SendPaymentModal />
<BasePage class="xl:pl-96">
<BasePageHeader :title="pageTitle">
<template #actions>
<BaseButton
v-if="userStore.hasAbilities(abilities.SEND_PAYMENT)"
:disabled="isSendingEmail"
:content-loading="isFetching"
variant="primary"
@click="onPaymentSend"
>
{{ $t('payments.send_payment_receipt') }}
</BaseButton>
<PaymentDropdown
:content-loading="isFetching"
class="ml-3"
:row="payment"
/>
</template>
</BasePageHeader>
<!-- 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-6
border border-gray-200 border-solid
"
>
<BaseInput
v-model="searchData.searchText"
:placeholder="$t('general.search')"
type="text"
@input="onSearch"
>
<BaseIcon name="SearchIcon" class="h-5" />
</BaseInput>
<div class="flex ml-3" role="group" aria-label="First group">
<BaseDropdown
position="bottom-start"
width-class="w-50"
position-class="left-0"
>
<template #activator>
<BaseButton variant="gray">
<BaseIcon name="FilterIcon" />
</BaseButton>
</template>
<div
class="
px-4
py-1
pb-2
mb-2
text-sm
border-b border-gray-200 border-solid
"
>
{{ $t('general.sort_by') }}
</div>
<div class="px-2">
<BaseDropdownItem class="pt-3 rounded-md hover:rounded-md">
<BaseInputGroup class="-mt-3 font-normal">
<BaseRadio
id="filter_invoice_number"
v-model="searchData.orderByField"
:label="$t('invoices.title')"
size="sm"
name="filter"
value="invoice_number"
@update:modelValue="onSearch"
/>
</BaseInputGroup>
</BaseDropdownItem>
</div>
<div class="px-2">
<BaseDropdownItem class="pt-3 rounded-md hover:rounded-md">
<BaseInputGroup class="-mt-3 font-normal">
<BaseRadio
v-model="searchData.orderByField"
:label="$t('payments.date')"
size="sm"
name="filter"
value="payment_date"
@update:modelValue="onSearch"
/>
</BaseInputGroup>
</BaseDropdownItem>
</div>
<div class="px-2">
<BaseDropdownItem class="pt-3 rounded-md hover:rounded-md">
<BaseInputGroup class="-mt-3 font-normal">
<BaseRadio
id="filter_payment_number"
v-model="searchData.orderByField"
:label="$t('payments.payment_number')"
size="sm"
name="filter"
value="payment_number"
@update:modelValue="onSearch"
/>
</BaseInputGroup>
</BaseDropdownItem>
</div>
</BaseDropdown>
<BaseButton class="ml-1" size="md" variant="gray" @click="sortData">
<BaseIcon v-if="getOrderBy" name="SortAscendingIcon" />
<BaseIcon v-else name="SortDescendingIcon" />
</BaseButton>
</div>
</div>
<div
v-if="paymentStore && paymentStore.payments"
class="
h-full
pb-32
overflow-y-scroll
border-l border-gray-200 border-solid
"
>
<div v-for="(payment, index) in paymentStore.payments" :key="index">
<router-link
v-if="payment && !isLoading"
:id="'payment-' + payment.id"
:to="`/admin/payments/${payment.id}/view`"
:class="[
'flex justify-between p-4 items-center cursor-pointer hover:bg-gray-100 border-l-4 border-transparent',
{
'bg-gray-100 border-l-4 border-primary-500 border-solid':
hasActiveUrl(payment.id),
},
]"
style="border-bottom: 1px solid rgba(185, 193, 209, 0.41)"
>
<div class="flex-2">
<BaseText
:text="payment?.customer?.name"
:length="30"
class="
pr-2
mb-2
text-sm
not-italic
font-normal
leading-5
text-black
capitalize
truncate
"
/>
<div
class="
mb-1
text-xs
not-italic
font-medium
leading-5
text-gray-500
capitalize
"
>
{{ payment?.payment_number }}
</div>
<div
class="
mb-1
text-xs
not-italic
font-medium
leading-5
text-gray-500
capitalize
"
>
{{ payment?.invoice_number }}
</div>
</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="payment?.amount"
:currency="payment.customer?.currency"
/>
<div class="text-sm text-right text-gray-500 non-italic">
{{ payment.formatted_payment_date }}
</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="!paymentStore?.payments?.length && !isLoading"
class="flex justify-center px-4 mt-5 text-sm text-gray-600"
>
{{ $t('payments.no_matching_payments') }}
</p>
</div>
</div>
<!-- pdf -->
<div
class="flex flex-col min-h-0 mt-8 overflow-hidden"
style="height: 75vh"
>
<iframe
v-if="shareableLink"
:src="shareableLink"
class="flex-1 border border-gray-400 border-solid rounded-md"
/>
</div>
</BasePage>
</template>
<script setup>
import { useI18n } from 'vue-i18n'
import { debounce } from 'lodash'
import { ref, reactive, computed, inject, onMounted, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { useDialogStore } from '@/scripts/stores/dialog'
import { usePaymentStore } from '@/scripts/admin/stores/payment'
import { useModalStore } from '@/scripts/stores/modal'
import PaymentDropdown from '@/scripts/admin/components/dropdowns/PaymentIndexDropdown.vue'
import moment from 'moment'
import { useUserStore } from '@/scripts/admin/stores/user'
import SendPaymentModal from '@/scripts/admin/components/modal-components/SendPaymentModal.vue'
import abilities from '@/scripts/admin/stub/abilities'
import LoadingIcon from '@/scripts/components/icons/LoadingIcon.vue'
const route = useRoute()
const router = useRouter()
const { t } = useI18n()
let id = ref(null)
let count = ref(null)
let payment = reactive({})
let currency = ref(null)
let searchData = reactive({
orderBy: null,
orderByField: null,
searchText: null,
})
let isSearching = ref(false)
let isSendingEmail = ref(false)
let isMarkingAsSent = ref(false)
let isLoading = ref(false)
let isFetching = ref(false)
const $utils = inject('utils')
const paymentStore = usePaymentStore()
const modalStore = useModalStore()
const userStore = useUserStore()
const pageTitle = computed(() => {
return payment.payment_number || ''
})
const getOrderBy = computed(() => {
if (searchData.orderBy === 'asc' || searchData.orderBy == null) {
return true
}
return false
})
const getOrderName = computed(() =>
getOrderBy.value ? t('general.ascending') : t('general.descending')
)
const shareableLink = computed(() => {
return payment.unique_hash ? `/payments/pdf/${payment.unique_hash}` : false
})
const paymentDate = computed(() => {
return moment(paymentStore?.selectedPayment?.payment_date).format(
'YYYY/MM/DD'
)
})
watch(route, () => {
loadPayment()
})
loadPayments()
loadPayment()
onSearch = debounce(onSearch, 500)
function hasActiveUrl(id) {
return route.params.id == id
}
function hasAbilities() {
return userStore.hasAbilities([
abilities.DELETE_PAYMENT,
abilities.EDIT_PAYMENT,
abilities.VIEW_PAYMENT,
])
}
const dialogStore = useDialogStore()
async function loadPayments() {
isLoading.value = true
await paymentStore.fetchPayments({ limit: 'all' })
isLoading.value = false
setTimeout(() => {
scrollToPayment()
}, 500)
}
async function loadPayment() {
if (!route.params.id) return
isFetching.value = true
let response = await paymentStore.fetchPayment(route.params.id)
if (response.data) {
isFetching.value = false
Object.assign(payment, response.data.data)
}
}
function scrollToPayment() {
const el = document.getElementById(`payment-${route.params.id}`)
if (el) {
el.scrollIntoView({ behavior: 'smooth' })
el.classList.add('shake')
}
}
async function onSearch() {
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
try {
let response = await paymentStore.searchPayment(data)
isSearching.value = false
if (response.data.data) {
paymentStore.payments = response.data.data
}
} catch (error) {
isSearching.value = false
}
}
function sortData() {
if (searchData.orderBy === 'asc') {
searchData.orderBy = 'desc'
onSearch()
return true
}
searchData.orderBy = 'asc'
onSearch()
return true
}
async function onPaymentSend() {
modalStore.openModal({
title: t('payments.send_payment'),
componentName: 'SendPaymentModal',
id: payment.id,
data: payment,
variant: 'lg',
})
}
</script>