mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-28 12:11:08 -04:00
add scroll to load invoices and fixed limited category and customer issue in payment and expense
This commit is contained in:
@ -17,6 +17,7 @@ export const useCategoryStore = (useWindow = false) => {
|
|||||||
name: '',
|
name: '',
|
||||||
description: '',
|
description: '',
|
||||||
},
|
},
|
||||||
|
editCategory: null
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getters: {
|
getters: {
|
||||||
|
|||||||
@ -25,6 +25,7 @@ export const useCustomerStore = (useWindow = false) => {
|
|||||||
currentCustomer: {
|
currentCustomer: {
|
||||||
...customerStub(),
|
...customerStub(),
|
||||||
},
|
},
|
||||||
|
editCustomer: null
|
||||||
}),
|
}),
|
||||||
|
|
||||||
getters: {
|
getters: {
|
||||||
|
|||||||
@ -77,6 +77,7 @@
|
|||||||
label="name"
|
label="name"
|
||||||
track-by="id"
|
track-by="id"
|
||||||
:options="searchCategory"
|
:options="searchCategory"
|
||||||
|
v-if="!isFetchingInitialData"
|
||||||
:filter-results="false"
|
:filter-results="false"
|
||||||
resolve-on-load
|
resolve-on-load
|
||||||
:delay="500"
|
:delay="500"
|
||||||
@ -180,6 +181,7 @@
|
|||||||
label="name"
|
label="name"
|
||||||
track-by="id"
|
track-by="id"
|
||||||
:options="searchCustomer"
|
:options="searchCustomer"
|
||||||
|
v-if="!isFetchingInitialData"
|
||||||
:filter-results="false"
|
:filter-results="false"
|
||||||
resolve-on-load
|
resolve-on-load
|
||||||
:delay="500"
|
:delay="500"
|
||||||
@ -280,7 +282,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted } from 'vue'
|
import { ref, computed, onMounted, onBeforeUnmount } from 'vue'
|
||||||
import { useRoute, useRouter } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import {
|
import {
|
||||||
@ -413,11 +415,25 @@ function onCurrencyChange(v) {
|
|||||||
|
|
||||||
async function searchCategory(search) {
|
async function searchCategory(search) {
|
||||||
let res = await categoryStore.fetchCategories({ search })
|
let res = await categoryStore.fetchCategories({ search })
|
||||||
|
if(res.data.data.length>0 && categoryStore.editCategory) {
|
||||||
|
let checkCategoryExist = res.data.data.find((c) => c.id==categoryStore.editCategory.id)
|
||||||
|
if(!checkCategoryExist) {
|
||||||
|
let edit_category = Object.assign({}, categoryStore.editCategory)
|
||||||
|
res.data.data.push(edit_category)
|
||||||
|
}
|
||||||
|
}
|
||||||
return res.data.data
|
return res.data.data
|
||||||
}
|
}
|
||||||
|
|
||||||
async function searchCustomer(search) {
|
async function searchCustomer(search) {
|
||||||
let res = await customerStore.fetchCustomers({ search })
|
let res = await customerStore.fetchCustomers({ search })
|
||||||
|
if(res.data.data.length>0 && customerStore.editCustomer) {
|
||||||
|
let checkCustomerExist = res.data.data.find((c) => c.id==customerStore.editCustomer.id)
|
||||||
|
if(!checkCustomerExist) {
|
||||||
|
let edit_customer = Object.assign({}, customerStore.editCustomer)
|
||||||
|
res.data.data.push(edit_customer)
|
||||||
|
}
|
||||||
|
}
|
||||||
return res.data.data
|
return res.data.data
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,10 +449,21 @@ async function loadData() {
|
|||||||
await expenseStore.fetchPaymentModes({ limit: 'all' })
|
await expenseStore.fetchPaymentModes({ limit: 'all' })
|
||||||
|
|
||||||
if (isEdit.value) {
|
if (isEdit.value) {
|
||||||
await expenseStore.fetchExpense(route.params.id)
|
const expenseData = await expenseStore.fetchExpense(route.params.id)
|
||||||
|
|
||||||
expenseStore.currentExpense.currency_id =
|
expenseStore.currentExpense.currency_id =
|
||||||
expenseStore.currentExpense.selectedCurrency.id
|
expenseStore.currentExpense.selectedCurrency.id
|
||||||
|
|
||||||
|
if(expenseData.data) {
|
||||||
|
if(!categoryStore.editCategory && expenseData.data.data.expense_category) {
|
||||||
|
categoryStore.editCategory = expenseData.data.data.expense_category
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!customerStore.editCustomer && expenseData.data.data.customer) {
|
||||||
|
customerStore.editCustomer = expenseData.data.data.customer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else if (route.query.customer) {
|
} else if (route.query.customer) {
|
||||||
expenseStore.currentExpense.customer_id = route.query.customer
|
expenseStore.currentExpense.customer_id = route.query.customer
|
||||||
}
|
}
|
||||||
@ -472,4 +499,10 @@ async function submitForm() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
expenseStore.resetCurrentExpenseData()
|
||||||
|
customerStore.editCustomer = null
|
||||||
|
categoryStore.editCategory = null
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -40,6 +40,10 @@ const isSendingEmail = ref(false)
|
|||||||
const isRequestOnGoing = ref(false)
|
const isRequestOnGoing = ref(false)
|
||||||
const isSearching = ref(false)
|
const isSearching = ref(false)
|
||||||
const isLoading = ref(false)
|
const isLoading = ref(false)
|
||||||
|
const invoiceList = ref(null)
|
||||||
|
const page_no = ref(1)
|
||||||
|
const last_page_no = ref(1)
|
||||||
|
const isLoadMore = ref(false)
|
||||||
|
|
||||||
const searchData = reactive({
|
const searchData = reactive({
|
||||||
orderBy: null,
|
orderBy: null,
|
||||||
@ -118,14 +122,38 @@ function hasActiveUrl(id) {
|
|||||||
return route.params.id == id
|
return route.params.id == id
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadInvoices() {
|
async function loadInvoices(params, isScroll=false) {
|
||||||
|
if(isScroll) {
|
||||||
|
isLoadMore.value = true
|
||||||
|
}
|
||||||
|
else {
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
await invoiceStore.fetchInvoices()
|
}
|
||||||
|
let invoice = await invoiceStore.fetchInvoices(params)
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
|
isLoadMore.value = false
|
||||||
|
let invoice_list = invoiceList.value ? invoiceList.value : []
|
||||||
|
|
||||||
|
for (const key in invoice.data.data) {
|
||||||
|
invoice_list.push(invoice.data.data[key])
|
||||||
|
}
|
||||||
|
invoiceList.value = invoice_list
|
||||||
|
|
||||||
|
page_no.value = params ? params.page : 1
|
||||||
|
last_page_no.value = invoice.data.meta.last_page
|
||||||
|
let isInvoiceExist = invoiceList.value.find(inv=>inv.id==route.params.id)
|
||||||
|
|
||||||
|
if(isScroll==false && !isInvoiceExist && page_no.value<last_page_no.value) {
|
||||||
|
loadInvoices({page: ++page_no.value})
|
||||||
|
}
|
||||||
|
|
||||||
|
if(isInvoiceExist) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
if(isScroll==false) {
|
||||||
scrollToInvoice()
|
scrollToInvoice()
|
||||||
|
}
|
||||||
}, 500)
|
}, 500)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function scrollToInvoice() {
|
function scrollToInvoice() {
|
||||||
@ -133,9 +161,21 @@ function scrollToInvoice() {
|
|||||||
if (el) {
|
if (el) {
|
||||||
el.scrollIntoView({ behavior: 'smooth' })
|
el.scrollIntoView({ behavior: 'smooth' })
|
||||||
el.classList.add('shake')
|
el.classList.add('shake')
|
||||||
|
addScrollListner()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addScrollListner() {
|
||||||
|
let el = document.getElementById("scroll_load")
|
||||||
|
el.addEventListener('scroll', (ev) => {
|
||||||
|
if(ev.target.scrollTop>0 && (ev.target.scrollTop == ev.target.scrollHeight - ev.target.clientHeight)) {
|
||||||
|
if(page_no.value<last_page_no.value) {
|
||||||
|
loadInvoices({page: ++page_no.value}, true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
async function loadInvoice() {
|
async function loadInvoice() {
|
||||||
let response = await invoiceStore.fetchInvoice(route.params.id)
|
let response = await invoiceStore.fetchInvoice(route.params.id)
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
@ -359,7 +399,7 @@ onSearched = debounce(onSearched, 500)
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
v-if="invoiceStore && invoiceStore.invoices"
|
v-if="invoiceStore && invoiceList"
|
||||||
class="
|
class="
|
||||||
h-full
|
h-full
|
||||||
pb-32
|
pb-32
|
||||||
@ -367,8 +407,10 @@ onSearched = debounce(onSearched, 500)
|
|||||||
border-l border-gray-200 border-solid
|
border-l border-gray-200 border-solid
|
||||||
base-scroll
|
base-scroll
|
||||||
"
|
"
|
||||||
|
id="scroll_load"
|
||||||
>
|
>
|
||||||
<div v-for="(invoice, index) in invoiceStore.invoices" :key="index">
|
|
||||||
|
<div v-for="(invoice, index) in invoiceList" :key="index">
|
||||||
<router-link
|
<router-link
|
||||||
v-if="invoice && !isLoading"
|
v-if="invoice && !isLoading"
|
||||||
:id="'invoice-' + invoice.id"
|
:id="'invoice-' + invoice.id"
|
||||||
@ -451,7 +493,7 @@ onSearched = debounce(onSearched, 500)
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex justify-center p-4 items-center">
|
<div class="flex justify-center p-4 items-center">
|
||||||
<LoadingIcon
|
<LoadingIcon
|
||||||
v-if="isLoading"
|
v-if="isLoading || isLoadMore"
|
||||||
class="h-6 m-1 animate-spin text-primary-400"
|
class="h-6 m-1 animate-spin text-primary-400"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -84,9 +84,9 @@
|
|||||||
<BaseCustomerSelectInput
|
<BaseCustomerSelectInput
|
||||||
v-model="paymentStore.currentPayment.customer_id"
|
v-model="paymentStore.currentPayment.customer_id"
|
||||||
:content-loading="isLoadingContent"
|
:content-loading="isLoadingContent"
|
||||||
|
v-if="!isLoadingContent"
|
||||||
:invalid="v$.currentPayment.customer_id.$error"
|
:invalid="v$.currentPayment.customer_id.$error"
|
||||||
:placeholder="$t('customers.select_a_customer')"
|
:placeholder="$t('customers.select_a_customer')"
|
||||||
:fetch-all="isEdit"
|
|
||||||
show-action
|
show-action
|
||||||
@update:modelValue="
|
@update:modelValue="
|
||||||
selectNewCustomer(paymentStore.currentPayment.customer_id)
|
selectNewCustomer(paymentStore.currentPayment.customer_id)
|
||||||
@ -446,6 +446,9 @@ function onCustomerChange(customer_id) {
|
|||||||
paymentStore.currentPayment.selectedCustomer = res2.data.data
|
paymentStore.currentPayment.selectedCustomer = res2.data.data
|
||||||
paymentStore.currentPayment.customer = res2.data.data
|
paymentStore.currentPayment.customer = res2.data.data
|
||||||
paymentStore.currentPayment.currency = res2.data.data.currency
|
paymentStore.currentPayment.currency = res2.data.data.currency
|
||||||
|
if(isEdit.value && !customerStore.editCustomer && paymentStore.currentPayment.customer_id) {
|
||||||
|
customerStore.editCustomer = res2.data.data
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (paymentStore.currentPayment.invoice_id) {
|
if (paymentStore.currentPayment.invoice_id) {
|
||||||
@ -482,6 +485,7 @@ function onCustomerChange(customer_id) {
|
|||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
paymentStore.resetCurrentPayment()
|
paymentStore.resetCurrentPayment()
|
||||||
invoiceList.value = []
|
invoiceList.value = []
|
||||||
|
customerStore.editCustomer = null
|
||||||
})
|
})
|
||||||
|
|
||||||
async function submitPaymentData() {
|
async function submitPaymentData() {
|
||||||
|
|||||||
@ -82,6 +82,13 @@ async function searchCustomers(search) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let res = await customerStore.fetchCustomers(data)
|
let res = await customerStore.fetchCustomers(data)
|
||||||
|
if(res.data.data.length>0 && customerStore.editCustomer) {
|
||||||
|
let checkCustomerExist = res.data.data.find((c) => c.id==customerStore.editCustomer.id)
|
||||||
|
if(!checkCustomerExist) {
|
||||||
|
let edit_customer = Object.assign({}, customerStore.editCustomer)
|
||||||
|
res.data.data.push(edit_customer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return res.data.data
|
return res.data.data
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user