From 0e31f85c181572d3e6c9dc253233722463085ee6 Mon Sep 17 00:00:00 2001 From: asift798 Date: Mon, 14 Mar 2022 12:55:38 +0530 Subject: [PATCH] change company currency if it does not have any transaction. --- resources/scripts/admin/stores/company.js | 14 ++++++++++++++ .../admin/views/settings/PreferencesSetting.vue | 13 +++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/resources/scripts/admin/stores/company.js b/resources/scripts/admin/stores/company.js index 1e10489b..f5462ae0 100644 --- a/resources/scripts/admin/stores/company.js +++ b/resources/scripts/admin/stores/company.js @@ -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) + }) + }) + }, }, })() } diff --git a/resources/scripts/admin/views/settings/PreferencesSetting.vue b/resources/scripts/admin/views/settings/PreferencesSetting.vue index 6c46f645..531cb83d 100644 --- a/resources/scripts/admin/views/settings/PreferencesSetting.vue +++ b/resources/scripts/admin/views/settings/PreferencesSetting.vue @@ -8,7 +8,11 @@ @@ -21,7 +25,7 @@ :searchable="true" track-by="name" :invalid="v$.currency.$error" - disabled + :disabled="isCurrencyDisabled" class="w-full" > @@ -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 }) }