change company currency if it does not have any transaction.

This commit is contained in:
asift798
2022-03-14 12:55:38 +05:30
parent e7301eb7a3
commit 0e31f85c18
2 changed files with 25 additions and 2 deletions

View File

@ -184,6 +184,20 @@ export const useCompanyStore = (useWindow = false) => {
setDefaultCurrency(data) {
this.defaultCurrency = data.currency
},
checkCompanyHasCurrencyTransactions() {
return new Promise((resolve, reject) => {
axios
.get(`/api/v1/company/has-transactions`)
.then((response) => {
resolve(response)
})
.catch((err) => {
handleError(err)
reject(err)
})
})
},
},
})()
}

View File

@ -8,7 +8,11 @@
<BaseInputGroup
:content-loading="isFetchingInitialData"
:label="$tc('settings.preferences.currency')"
:help-text="$t('settings.preferences.company_currency_unchangeable')"
:help-text="
isCurrencyDisabled
? $t('settings.preferences.company_currency_unchangeable')
: ''
"
:error="v$.currency.$error && v$.currency.$errors[0].$message"
required
>
@ -21,7 +25,7 @@
:searchable="true"
track-by="name"
:invalid="v$.currency.$error"
disabled
:disabled="isCurrencyDisabled"
class="w-full"
>
</BaseMultiselect>
@ -187,6 +191,7 @@ const { t, tm } = useI18n()
let isSaving = ref(false)
let isDataSaving = ref(false)
let isFetchingInitialData = ref(false)
let isCurrencyDisabled = ref(true)
const settingsForm = reactive({ ...companyStore.selectedCompanySettings })
@ -282,10 +287,14 @@ setInitialData()
async function setInitialData() {
isFetchingInitialData.value = true
Promise.all([
companyStore.checkCompanyHasCurrencyTransactions(),
globalStore.fetchCurrencies(),
globalStore.fetchDateFormats(),
globalStore.fetchTimeZones(),
]).then(([res1]) => {
if (res1.data?.has_transactions == false) {
isCurrencyDisabled.value = false
}
isFetchingInitialData.value = false
})
}