Merge branch 'mark-as-default-template' into 'master'

added mark as default changes in estimate and invoice template

See merge request mohit.panjvani/crater-web!1440
This commit is contained in:
Mohit Panjwani
2022-02-15 06:16:57 +00:00
9 changed files with 79 additions and 3 deletions

View File

@ -31,6 +31,10 @@ const props = defineProps({
type: String,
default: '',
},
isMarkAsDefault: {
type: Boolean,
default: false,
},
})
const modalStore = useModalStore()
@ -38,6 +42,17 @@ const modalStore = useModalStore()
const { t } = useI18n()
function openTemplateModal() {
let markAsDefaultDescription = ''
if (props.storeProp == 'newEstimate') {
markAsDefaultDescription = t(
'estimates.mark_as_default_estimate_template_description'
)
} else if (props.storeProp == 'newInvoice') {
markAsDefaultDescription = t(
'invoices.mark_as_default_invoice_template_description'
)
}
modalStore.openModal({
title: t('general.choose_template'),
componentName: 'SelectTemplate',
@ -45,6 +60,8 @@ function openTemplateModal() {
templates: props.store.templates,
store: props.store,
storeProp: props.storeProp,
isMarkAsDefault: props.isMarkAsDefault,
markAsDefaultDescription,
},
})
}

View File

@ -58,7 +58,18 @@
</span>
</div>
</div>
<div v-if="!modalStore.data.store.isEdit" class="z-0 flex ml-3 pt-5">
<BaseCheckbox
v-model="modalStore.data.isMarkAsDefault"
:set-initial-value="false"
variant="primary"
:label="$t('general.mark_as_default')"
:description="modalStore.data.markAsDefaultDescription"
/>
</div>
</div>
<div class="z-0 flex justify-end p-4 border-t border-gray-200 border-solid">
<BaseButton class="mr-3" variant="primary-outline" @click="closeModal">
{{ $t('general.cancel') }}
@ -76,8 +87,10 @@
<script setup>
import { ref, computed } from 'vue'
import { useModalStore } from '@/scripts/stores/modal'
import { useUserStore } from '@/scripts/admin/stores/user'
const modalStore = useModalStore()
const userStore = useUserStore()
const selectedTemplate = ref('')
@ -100,6 +113,22 @@ function setData() {
async function chooseTemplate() {
await modalStore.data.store.setTemplate(selectedTemplate.value)
// update default estimate or invoice template
if (!modalStore.data.store.isEdit && modalStore.data.isMarkAsDefault) {
if (modalStore.data.storeProp == 'newEstimate') {
await userStore.updateUserSettings({
settings: {
default_estimate_template: selectedTemplate.value,
},
})
} else if (modalStore.data.storeProp == 'newInvoice') {
await userStore.updateUserSettings({
settings: {
default_invoice_template: selectedTemplate.value,
},
})
}
}
closeModal()
}

View File

@ -13,6 +13,7 @@ import { handleError } from '@/scripts/helpers/error-handling'
import estimateStub from '../stub/estimate'
import estimateItemStub from '../stub/estimate-item'
import taxStub from '../stub/tax'
import { useUserStore } from './user'
export const useEstimateStore = (useWindow = false) => {
const defineStoreFunc = useWindow ? window.pinia.defineStore : defineStore
@ -497,6 +498,7 @@ export const useEstimateStore = (useWindow = false) => {
const itemStore = useItemStore()
const taxTypeStore = useTaxTypeStore()
const route = useRoute()
const userStore = useUserStore()
this.isFetchingInitialSettings = true
this.newEstimate.selectedCurrency = companyStore.selectedCompanyCurrency
@ -546,6 +548,9 @@ export const useEstimateStore = (useWindow = false) => {
}
this.setTemplate(this.templates[0].name)
this.newEstimate.template_name =
userStore.currentUserSettings.default_estimate_template ?
userStore.currentUserSettings.default_estimate_template : this.newEstimate.template_name
}
if (isEdit) {

View File

@ -14,6 +14,7 @@ import { useCustomerStore } from './customer'
import { useTaxTypeStore } from './tax-type'
import { useCompanyStore } from './company'
import { useItemStore } from './item'
import { useUserStore } from './user'
export const useInvoiceStore = (useWindow = false) => {
const defineStoreFunc = useWindow ? window.pinia.defineStore : defineStore
@ -445,6 +446,7 @@ export const useInvoiceStore = (useWindow = false) => {
const itemStore = useItemStore()
const taxTypeStore = useTaxTypeStore()
const route = useRoute()
const userStore = useUserStore()
this.isFetchingInitialSettings = true
@ -495,6 +497,9 @@ export const useInvoiceStore = (useWindow = false) => {
if (res3.data) {
this.setTemplate(this.templates[0].name)
this.newInvoice.template_name =
userStore.currentUserSettings.default_invoice_template ?
userStore.currentUserSettings.default_invoice_template : this.newInvoice.template_name
}
}
if (isEdit) {

View File

@ -108,6 +108,14 @@ export const useUserStore = (useWindow = false) => {
this.currentUserSettings.language = data.settings.language
global.locale = data.settings.language
}
if (data.settings.default_estimate_template) {
this.currentUserSettings.default_estimate_template =
data.settings.default_estimate_template
}
if (data.settings.default_invoice_template) {
this.currentUserSettings.default_invoice_template =
data.settings.default_invoice_template
}
resolve(response)
})
.catch((err) => {

View File

@ -119,6 +119,7 @@
:store="estimateStore"
component-name="EstimateTemplate"
store-prop="newEstimate"
:is-mark-as-default="isMarkAsDefault"
/>
</div>
@ -171,6 +172,7 @@ const { t } = useI18n()
const estimateValidationScope = 'newEstimate'
let isSaving = ref(false)
const isMarkAsDefault = ref(false)
const estimateNoteFieldList = ref([
'customer',

View File

@ -118,6 +118,7 @@
:store="invoiceStore"
store-prop="newInvoice"
component-name="InvoiceTemplate"
:is-mark-as-default="isMarkAsDefault"
/>
</div>
@ -173,6 +174,7 @@ let router = useRouter()
const invoiceValidationScope = 'newInvoice'
let isSaving = ref(false)
const isMarkAsDefault = ref(false)
const invoiceNoteFieldList = ref([
'customer',

View File

@ -20,6 +20,7 @@
>
{{ label }}
</label>
<p v-if="description" class="text-gray-500">{{ description }}</p>
</div>
</div>
</template>
@ -32,6 +33,10 @@ const props = defineProps({
type: String,
default: '',
},
description: {
type: String,
default: '',
},
modelValue: {
type: [Boolean, Array],
default: false,

View File

@ -99,7 +99,8 @@
"note": "Note",
"pay_invoice": "Pay Invoice",
"login_successfully": "Logged in successfully!",
"logged_out_successfully": "Logged out successfully"
"logged_out_successfully": "Logged out successfully",
"mark_as_default": "Mark as default"
},
"dashboard": {
"select_year": "Select year",
@ -353,7 +354,8 @@
"amount": "Amount",
"select_an_item": "Type or click to select an item",
"type_item_description": "Type Item Description (optional)"
}
},
"mark_as_default_estimate_template_description": "If enabled, the selected template will be automatically selected for new estimates."
},
"invoices": {
"title": "Invoices",
@ -444,7 +446,8 @@
"deleted_message": "Invoice deleted successfully | Invoices deleted successfully",
"marked_as_sent_message": "Invoice marked as sent successfully",
"something_went_wrong": "something went wrong",
"invalid_due_amount_message": "Total Invoice amount cannot be less than total paid amount for this Invoice. Please update the invoice or delete the associated payments to continue."
"invalid_due_amount_message": "Total Invoice amount cannot be less than total paid amount for this Invoice. Please update the invoice or delete the associated payments to continue.",
"mark_as_default_invoice_template_description": "If enabled, the selected template will be automatically selected for new invoices."
},
"recurring_invoices": {
"title": "Recurring Invoices",