diff --git a/src/components/ToolBar.vue b/src/components/ToolBar.vue index 2430ed6..b913c4f 100644 --- a/src/components/ToolBar.vue +++ b/src/components/ToolBar.vue @@ -3,6 +3,7 @@ import { ref, watch } from 'vue' import { useCounterMixin } from '@/stores/mixin' import { useChekIn } from '@/stores/chekin' +import { calculateFiscalYear } from '@/utils/function' import type { DataDateMonthObject } from '@/interface/index/Main' @@ -27,7 +28,7 @@ const props = defineProps({ const emit = defineEmits(['update:year']) const filterYear = ref( - stores.year ? stores.year : new Date().getFullYear() + stores.year ? stores.year : calculateFiscalYear(new Date()) ) //ปีงบประมาณ const titleName = ref('เพิ่มรายการลงเวลากรณีพิเศษ') //หัว popup const dateMonth = ref({ diff --git a/src/stores/chekin.ts b/src/stores/chekin.ts index 1182ff7..bf27004 100644 --- a/src/stores/chekin.ts +++ b/src/stores/chekin.ts @@ -2,13 +2,14 @@ import { defineStore } from 'pinia' import { ref } from 'vue' import type { FormData, Datalist } from '@/interface/response/checkin' import { useCounterMixin } from '@/stores/mixin' +import { calculateFiscalYear } from '@/utils/function' const mixin = useCounterMixin() const { date2Thai } = mixin /** store for checkin history*/ export const useChekIn = defineStore('checkin', () => { - const year = ref(new Date().getFullYear()) + const year = ref(calculateFiscalYear(new Date())) //ปีงบประมาณ const rows = ref([]) const tab = ref('history') diff --git a/src/utils/function.ts b/src/utils/function.ts new file mode 100644 index 0000000..02f422c --- /dev/null +++ b/src/utils/function.ts @@ -0,0 +1,10 @@ +/** + * คำนวณปีงบประมาณ + * + * @param date วันที่ปัจจุบัน + * @returns ปีงบประมาณ + */ +export function calculateFiscalYear(date: Date) { + const month = date.getMonth() + 1 + return month >= 10 ? date.getFullYear() + 1 : date.getFullYear() +}