support scheduled transaction (#2)

This commit is contained in:
MaysWind
2024-08-26 01:52:52 +08:00
parent 17d4fec256
commit d2eaf5c6da
42 changed files with 1437 additions and 112 deletions
+6
View File
@@ -130,6 +130,12 @@ export function isObjectEmpty(obj) {
return true;
}
export function sortNumbersArray(array) {
return array.sort(function (num1, num2) {
return num1 - num2;
});
}
export function getObjectOwnFieldCount(object) {
let count = 0;
+76 -3
View File
@@ -9,6 +9,7 @@ import colorConstants from '@/consts/color.js';
import accountConstants from '@/consts/account.js';
import categoryConstants from '@/consts/category.js';
import transactionConstants from '@/consts/transaction.js';
import templateConstants from '@/consts/template.js';
import statisticsConstants from '@/consts/statistics.js';
import apiConstants from '@/consts/api.js';
@@ -17,6 +18,7 @@ import {
isString,
isNumber,
isBoolean,
getNameByKeyValue,
copyObjectTo,
copyArrayTo
} from './common.js';
@@ -311,6 +313,16 @@ function getMonthLongName(monthName, translateFn) {
return translateFn(`datetime.${monthName}.long`);
}
function getMonthdayOrdinal(monthDay, translateFn) {
return translateFn(`datetime.monthDayOrdinal.${monthDay}`);
}
function getMonthdayShortName(monthDay, translateFn) {
return translateFn('format.misc.monthDay', {
ordinal: getMonthdayOrdinal(monthDay, translateFn)
});
}
function getWeekdayShortName(weekDayName, translateFn) {
return translateFn(`datetime.${weekDayName}.short`);
}
@@ -319,6 +331,30 @@ function getWeekdayLongName(weekDayName, translateFn) {
return translateFn(`datetime.${weekDayName}.long`);
}
function getMultiMonthdayShortNames(monthDays, translateFn) {
if (!monthDays) {
return '';
}
if (monthDays.length === 1) {
return translateFn('format.misc.monthDay', {
ordinal: getMonthdayOrdinal(monthDays[0], translateFn)
});
} else {
return translateFn('format.misc.monthDays', {
multiMonthDays: joinMultiText(monthDays.map(monthDay =>
translateFn('format.misc.eachMonthDayInMonthDays', {
ordinal: getMonthdayOrdinal(monthDay, translateFn)
})), translateFn)
});
}
}
function getMultiWeekdayLongNames(weekdayTypes, translateFn) {
const allWeekDays = getAllWeekDays(null, translateFn)
return joinMultiText(weekdayTypes.map(type => getNameByKeyValue(allWeekDays, type, 'type', 'displayName')), translateFn);
}
function getI18nLongDateFormat(translateFn, formatTypeValue) {
const defaultLongDateFormatTypeName = translateFn('default.longDateFormat');
return getDateTimeFormat(translateFn, datetimeConstants.allLongDateFormat, datetimeConstants.allLongDateFormatArray, 'format.longDate', defaultLongDateFormatTypeName, datetimeConstants.defaultLongDateFormat, formatTypeValue);
@@ -534,10 +570,23 @@ function getAllCurrencies(translateFn) {
return allCurrencies;
}
function getAllWeekDays(translateFn) {
function getAllWeekDays(firstDayOfWeek, translateFn) {
const allWeekDays = [];
for (let i = 0; i < datetimeConstants.allWeekDaysArray.length; i++) {
if (!isNumber(firstDayOfWeek)) {
firstDayOfWeek = datetimeConstants.allWeekDays.Sunday.type;
}
for (let i = firstDayOfWeek; i < datetimeConstants.allWeekDaysArray.length; i++) {
const weekDay = datetimeConstants.allWeekDaysArray[i];
allWeekDays.push({
type: weekDay.type,
displayName: translateFn(`datetime.${weekDay.name}.long`)
});
}
for (let i = 0; i < firstDayOfWeek; i++) {
const weekDay = datetimeConstants.allWeekDaysArray[i];
allWeekDays.push({
@@ -1078,6 +1127,25 @@ function getAllTransactionEditScopeTypes(translateFn) {
return allEditScopeTypes;
}
function getAllTransactionScheduledFrequencyTypes(translateFn) {
const allScheduledFrequencyTypes = [];
for (const typeName in templateConstants.allTemplateScheduledFrequencyTypes) {
if (!Object.prototype.hasOwnProperty.call(templateConstants.allTemplateScheduledFrequencyTypes, typeName)) {
continue;
}
const frequencyType = templateConstants.allTemplateScheduledFrequencyTypes[typeName];
allScheduledFrequencyTypes.push({
type: frequencyType.type,
displayName: translateFn(frequencyType.name)
});
}
return allScheduledFrequencyTypes;
}
function getAllTransactionDefaultCategories(categoryType, locale, translateFn) {
const allCategories = {};
const categoryTypes = [];
@@ -1442,8 +1510,12 @@ export function i18nFunctions(i18nGlobal) {
getAllShortTimeFormats: () => getAllShortTimeFormats(i18nGlobal.t),
getMonthShortName: (month) => getMonthShortName(month, i18nGlobal.t),
getMonthLongName: (month) => getMonthLongName(month, i18nGlobal.t),
getMonthdayOrdinal: (monthDay) => getMonthdayOrdinal(monthDay, i18nGlobal.t),
getMonthdayShortName: (monthDay) => getMonthdayShortName(monthDay, i18nGlobal.t),
getWeekdayShortName: (weekDay) => getWeekdayShortName(weekDay, i18nGlobal.t),
getWeekdayLongName: (weekDay) => getWeekdayLongName(weekDay, i18nGlobal.t),
getMultiMonthdayShortNames: (monthdays) => getMultiMonthdayShortNames(monthdays, i18nGlobal.t),
getMultiWeekdayLongNames: (weekdayTypes) => getMultiWeekdayLongNames(weekdayTypes, i18nGlobal.t),
formatUnixTimeToLongDateTime: (userStore, unixTime, utcOffset, currentUtcOffset) => formatUnixTime(unixTime, getI18nLongDateFormat(i18nGlobal.t, userStore.currentUserLongDateFormat) + ' ' + getI18nLongTimeFormat(i18nGlobal.t, userStore.currentUserLongTimeFormat), utcOffset, currentUtcOffset),
formatUnixTimeToShortDateTime: (userStore, unixTime, utcOffset, currentUtcOffset) => formatUnixTime(unixTime, getI18nShortDateFormat(i18nGlobal.t, userStore.currentUserShortDateFormat) + ' ' + getI18nShortTimeFormat(i18nGlobal.t, userStore.currentUserShortTimeFormat), utcOffset, currentUtcOffset),
formatUnixTimeToLongDate: (userStore, unixTime, utcOffset, currentUtcOffset) => formatUnixTime(unixTime, getI18nLongDateFormat(i18nGlobal.t, userStore.currentUserLongDateFormat), utcOffset, currentUtcOffset),
@@ -1465,7 +1537,7 @@ export function i18nFunctions(i18nGlobal) {
getAllTimezones: (includeSystemDefault) => getAllTimezones(includeSystemDefault, i18nGlobal.t),
getTimezoneDifferenceDisplayText: (utcOffset) => getTimezoneDifferenceDisplayText(utcOffset, i18nGlobal.t),
getAllCurrencies: () => getAllCurrencies(i18nGlobal.t),
getAllWeekDays: () => getAllWeekDays(i18nGlobal.t),
getAllWeekDays: (firstDayOfWeek) => getAllWeekDays(firstDayOfWeek, i18nGlobal.t),
getAllDateRanges: (scene, includeCustom) => getAllDateRanges(scene, includeCustom, i18nGlobal.t),
getAllRecentMonthDateRanges: (userStore, includeAll, includeCustom) => getAllRecentMonthDateRanges(userStore, includeAll, includeCustom, i18nGlobal.t),
getDateRangeDisplayName: (userStore, dateType, startTime, endTime) => getDateRangeDisplayName(userStore, dateType, startTime, endTime, i18nGlobal.t),
@@ -1493,6 +1565,7 @@ export function i18nFunctions(i18nGlobal) {
getAllStatisticsChartDataTypes: (analysisType) => getAllStatisticsChartDataTypes(i18nGlobal.t, analysisType),
getAllStatisticsSortingTypes: () => getAllStatisticsSortingTypes(i18nGlobal.t),
getAllTransactionEditScopeTypes: () => getAllTransactionEditScopeTypes(i18nGlobal.t),
getAllTransactionScheduledFrequencyTypes: () => getAllTransactionScheduledFrequencyTypes(i18nGlobal.t),
getAllTransactionDefaultCategories: (categoryType, locale) => getAllTransactionDefaultCategories(categoryType, locale, i18nGlobal.t),
getAllDisplayExchangeRates: (exchangeRatesData) => getAllDisplayExchangeRates(exchangeRatesData, i18nGlobal.t),
getEnableDisableOptions: () => getEnableDisableOptions(i18nGlobal.t),
+4
View File
@@ -41,6 +41,10 @@ export function isUserVerifyEmailEnabled() {
return getServerSetting('v') === '1';
}
export function isUserScheduledTransactionEnabled() {
return getServerSetting('s') === '1';
}
export function isDataExportingEnabled() {
return getServerSetting('e') === '1';
}
+9 -3
View File
@@ -523,7 +523,7 @@ export default {
getTransactionTemplate: ({ id }) => {
return axios.get('v1/transaction/templates/get.json?id=' + id);
},
addTransactionTemplate: ({ templateType, name, type, categoryId, sourceAccountId, destinationAccountId, sourceAmount, destinationAmount, hideAmount, tagIds, comment, clientSessionId }) => {
addTransactionTemplate: ({ templateType, name, type, categoryId, sourceAccountId, destinationAccountId, sourceAmount, destinationAmount, hideAmount, tagIds, comment, scheduledFrequencyType, scheduledFrequency, utcOffset, clientSessionId }) => {
return axios.post('v1/transaction/templates/add.json', {
templateType,
name,
@@ -536,10 +536,13 @@ export default {
hideAmount,
tagIds,
comment,
scheduledFrequencyType,
scheduledFrequency,
utcOffset,
clientSessionId
});
},
modifyTransactionTemplate: ({ id, name, type, categoryId, sourceAccountId, destinationAccountId, sourceAmount, destinationAmount, hideAmount, tagIds, comment }) => {
modifyTransactionTemplate: ({ id, name, type, categoryId, sourceAccountId, destinationAccountId, sourceAmount, destinationAmount, hideAmount, tagIds, comment, scheduledFrequencyType, scheduledFrequency, utcOffset }) => {
return axios.post('v1/transaction/templates/modify.json', {
id,
name,
@@ -551,7 +554,10 @@ export default {
destinationAmount,
hideAmount,
tagIds,
comment
comment,
scheduledFrequencyType,
scheduledFrequency,
utcOffset
});
},
hideTransactionTemplate: ({ id, hidden }) => {