mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
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:
@ -31,6 +31,10 @@ const props = defineProps({
|
|||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
isMarkAsDefault: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
const modalStore = useModalStore()
|
const modalStore = useModalStore()
|
||||||
@ -38,6 +42,17 @@ const modalStore = useModalStore()
|
|||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
function openTemplateModal() {
|
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({
|
modalStore.openModal({
|
||||||
title: t('general.choose_template'),
|
title: t('general.choose_template'),
|
||||||
componentName: 'SelectTemplate',
|
componentName: 'SelectTemplate',
|
||||||
@ -45,6 +60,8 @@ function openTemplateModal() {
|
|||||||
templates: props.store.templates,
|
templates: props.store.templates,
|
||||||
store: props.store,
|
store: props.store,
|
||||||
storeProp: props.storeProp,
|
storeProp: props.storeProp,
|
||||||
|
isMarkAsDefault: props.isMarkAsDefault,
|
||||||
|
markAsDefaultDescription,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,7 +58,18 @@
|
|||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</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>
|
||||||
|
|
||||||
<div class="z-0 flex justify-end p-4 border-t border-gray-200 border-solid">
|
<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">
|
<BaseButton class="mr-3" variant="primary-outline" @click="closeModal">
|
||||||
{{ $t('general.cancel') }}
|
{{ $t('general.cancel') }}
|
||||||
@ -76,8 +87,10 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed } from 'vue'
|
import { ref, computed } from 'vue'
|
||||||
import { useModalStore } from '@/scripts/stores/modal'
|
import { useModalStore } from '@/scripts/stores/modal'
|
||||||
|
import { useUserStore } from '@/scripts/admin/stores/user'
|
||||||
|
|
||||||
const modalStore = useModalStore()
|
const modalStore = useModalStore()
|
||||||
|
const userStore = useUserStore()
|
||||||
|
|
||||||
const selectedTemplate = ref('')
|
const selectedTemplate = ref('')
|
||||||
|
|
||||||
@ -100,6 +113,22 @@ function setData() {
|
|||||||
|
|
||||||
async function chooseTemplate() {
|
async function chooseTemplate() {
|
||||||
await modalStore.data.store.setTemplate(selectedTemplate.value)
|
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()
|
closeModal()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import { handleError } from '@/scripts/helpers/error-handling'
|
|||||||
import estimateStub from '../stub/estimate'
|
import estimateStub from '../stub/estimate'
|
||||||
import estimateItemStub from '../stub/estimate-item'
|
import estimateItemStub from '../stub/estimate-item'
|
||||||
import taxStub from '../stub/tax'
|
import taxStub from '../stub/tax'
|
||||||
|
import { useUserStore } from './user'
|
||||||
|
|
||||||
export const useEstimateStore = (useWindow = false) => {
|
export const useEstimateStore = (useWindow = false) => {
|
||||||
const defineStoreFunc = useWindow ? window.pinia.defineStore : defineStore
|
const defineStoreFunc = useWindow ? window.pinia.defineStore : defineStore
|
||||||
@ -497,6 +498,7 @@ export const useEstimateStore = (useWindow = false) => {
|
|||||||
const itemStore = useItemStore()
|
const itemStore = useItemStore()
|
||||||
const taxTypeStore = useTaxTypeStore()
|
const taxTypeStore = useTaxTypeStore()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
const userStore = useUserStore()
|
||||||
|
|
||||||
this.isFetchingInitialSettings = true
|
this.isFetchingInitialSettings = true
|
||||||
this.newEstimate.selectedCurrency = companyStore.selectedCompanyCurrency
|
this.newEstimate.selectedCurrency = companyStore.selectedCompanyCurrency
|
||||||
@ -546,6 +548,9 @@ export const useEstimateStore = (useWindow = false) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.setTemplate(this.templates[0].name)
|
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) {
|
if (isEdit) {
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import { useCustomerStore } from './customer'
|
|||||||
import { useTaxTypeStore } from './tax-type'
|
import { useTaxTypeStore } from './tax-type'
|
||||||
import { useCompanyStore } from './company'
|
import { useCompanyStore } from './company'
|
||||||
import { useItemStore } from './item'
|
import { useItemStore } from './item'
|
||||||
|
import { useUserStore } from './user'
|
||||||
|
|
||||||
export const useInvoiceStore = (useWindow = false) => {
|
export const useInvoiceStore = (useWindow = false) => {
|
||||||
const defineStoreFunc = useWindow ? window.pinia.defineStore : defineStore
|
const defineStoreFunc = useWindow ? window.pinia.defineStore : defineStore
|
||||||
@ -445,6 +446,7 @@ export const useInvoiceStore = (useWindow = false) => {
|
|||||||
const itemStore = useItemStore()
|
const itemStore = useItemStore()
|
||||||
const taxTypeStore = useTaxTypeStore()
|
const taxTypeStore = useTaxTypeStore()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
const userStore = useUserStore()
|
||||||
|
|
||||||
this.isFetchingInitialSettings = true
|
this.isFetchingInitialSettings = true
|
||||||
|
|
||||||
@ -495,6 +497,9 @@ export const useInvoiceStore = (useWindow = false) => {
|
|||||||
|
|
||||||
if (res3.data) {
|
if (res3.data) {
|
||||||
this.setTemplate(this.templates[0].name)
|
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) {
|
if (isEdit) {
|
||||||
|
|||||||
@ -108,6 +108,14 @@ export const useUserStore = (useWindow = false) => {
|
|||||||
this.currentUserSettings.language = data.settings.language
|
this.currentUserSettings.language = data.settings.language
|
||||||
global.locale = 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)
|
resolve(response)
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
|||||||
@ -119,6 +119,7 @@
|
|||||||
:store="estimateStore"
|
:store="estimateStore"
|
||||||
component-name="EstimateTemplate"
|
component-name="EstimateTemplate"
|
||||||
store-prop="newEstimate"
|
store-prop="newEstimate"
|
||||||
|
:is-mark-as-default="isMarkAsDefault"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -171,6 +172,7 @@ const { t } = useI18n()
|
|||||||
|
|
||||||
const estimateValidationScope = 'newEstimate'
|
const estimateValidationScope = 'newEstimate'
|
||||||
let isSaving = ref(false)
|
let isSaving = ref(false)
|
||||||
|
const isMarkAsDefault = ref(false)
|
||||||
|
|
||||||
const estimateNoteFieldList = ref([
|
const estimateNoteFieldList = ref([
|
||||||
'customer',
|
'customer',
|
||||||
|
|||||||
@ -118,6 +118,7 @@
|
|||||||
:store="invoiceStore"
|
:store="invoiceStore"
|
||||||
store-prop="newInvoice"
|
store-prop="newInvoice"
|
||||||
component-name="InvoiceTemplate"
|
component-name="InvoiceTemplate"
|
||||||
|
:is-mark-as-default="isMarkAsDefault"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -173,6 +174,7 @@ let router = useRouter()
|
|||||||
|
|
||||||
const invoiceValidationScope = 'newInvoice'
|
const invoiceValidationScope = 'newInvoice'
|
||||||
let isSaving = ref(false)
|
let isSaving = ref(false)
|
||||||
|
const isMarkAsDefault = ref(false)
|
||||||
|
|
||||||
const invoiceNoteFieldList = ref([
|
const invoiceNoteFieldList = ref([
|
||||||
'customer',
|
'customer',
|
||||||
|
|||||||
@ -20,6 +20,7 @@
|
|||||||
>
|
>
|
||||||
{{ label }}
|
{{ label }}
|
||||||
</label>
|
</label>
|
||||||
|
<p v-if="description" class="text-gray-500">{{ description }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -32,6 +33,10 @@ const props = defineProps({
|
|||||||
type: String,
|
type: String,
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
|
description: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
modelValue: {
|
modelValue: {
|
||||||
type: [Boolean, Array],
|
type: [Boolean, Array],
|
||||||
default: false,
|
default: false,
|
||||||
|
|||||||
@ -99,7 +99,8 @@
|
|||||||
"note": "Note",
|
"note": "Note",
|
||||||
"pay_invoice": "Pay Invoice",
|
"pay_invoice": "Pay Invoice",
|
||||||
"login_successfully": "Logged in successfully!",
|
"login_successfully": "Logged in successfully!",
|
||||||
"logged_out_successfully": "Logged out successfully"
|
"logged_out_successfully": "Logged out successfully",
|
||||||
|
"mark_as_default": "Mark as default"
|
||||||
},
|
},
|
||||||
"dashboard": {
|
"dashboard": {
|
||||||
"select_year": "Select year",
|
"select_year": "Select year",
|
||||||
@ -353,7 +354,8 @@
|
|||||||
"amount": "Amount",
|
"amount": "Amount",
|
||||||
"select_an_item": "Type or click to select an item",
|
"select_an_item": "Type or click to select an item",
|
||||||
"type_item_description": "Type Item Description (optional)"
|
"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": {
|
"invoices": {
|
||||||
"title": "Invoices",
|
"title": "Invoices",
|
||||||
@ -444,7 +446,8 @@
|
|||||||
"deleted_message": "Invoice deleted successfully | Invoices deleted successfully",
|
"deleted_message": "Invoice deleted successfully | Invoices deleted successfully",
|
||||||
"marked_as_sent_message": "Invoice marked as sent successfully",
|
"marked_as_sent_message": "Invoice marked as sent successfully",
|
||||||
"something_went_wrong": "something went wrong",
|
"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": {
|
"recurring_invoices": {
|
||||||
"title": "Recurring Invoices",
|
"title": "Recurring Invoices",
|
||||||
|
|||||||
Reference in New Issue
Block a user