mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-14 06:57:35 +08:00
code refactor
This commit is contained in:
@@ -7,6 +7,7 @@ import { TransactionPicture } from '@/models/transaction_picture_info.ts';
|
||||
import { Transaction } from '@/models/transaction.ts';
|
||||
|
||||
import {
|
||||
isDefined,
|
||||
isNumber
|
||||
} from './common.ts';
|
||||
import {
|
||||
@@ -21,6 +22,7 @@ import {
|
||||
} from './category.ts';
|
||||
|
||||
export interface SetTransactionOptions {
|
||||
time?: number;
|
||||
type?: number;
|
||||
categoryId?: string;
|
||||
accountId?: string;
|
||||
@@ -32,6 +34,10 @@ export interface SetTransactionOptions {
|
||||
}
|
||||
|
||||
export function setTransactionModelByTransaction(transaction: Transaction, transaction2: Transaction | null | undefined, allCategories: Record<number, TransactionCategory[]>, allCategoriesMap: Record<string, TransactionCategory>, allVisibleAccounts: Account[], allAccountsMap: Record<string, Account>, allTagsMap: Record<string, TransactionTag>, defaultAccountId: string, options: SetTransactionOptions, setContextData: boolean, convertContextTime: boolean): void {
|
||||
if (isDefined(options.time)) {
|
||||
transaction.time = options.time;
|
||||
}
|
||||
|
||||
if (!options.type && options.categoryId && options.categoryId !== '0' && allCategoriesMap[options.categoryId]) {
|
||||
const category = allCategoriesMap[options.categoryId];
|
||||
const type = categoryTypeToTransactionType(category.type);
|
||||
@@ -41,6 +47,14 @@ export function setTransactionModelByTransaction(transaction: Transaction, trans
|
||||
}
|
||||
}
|
||||
|
||||
if (isDefined(options.amount)) {
|
||||
transaction.sourceAmount = options.amount;
|
||||
}
|
||||
|
||||
if (isDefined(options.destinationAmount)) {
|
||||
transaction.destinationAmount = options.destinationAmount;
|
||||
}
|
||||
|
||||
if (allCategories[CategoryType.Expense] &&
|
||||
allCategories[CategoryType.Expense].length) {
|
||||
if (options.categoryId && options.categoryId !== '0') {
|
||||
|
||||
@@ -442,14 +442,11 @@ function updateClosingBalance(): void {
|
||||
}
|
||||
|
||||
const currentUnixTime = getCurrentUnixTime();
|
||||
let setTransactionTime = false;
|
||||
let newTransactionTime: number | undefined = undefined;
|
||||
|
||||
if (endTime.value < currentUnixTime) {
|
||||
setTransactionTime = true;
|
||||
newTransactionTime = endTime.value;
|
||||
} else if (currentUnixTime < startTime.value) {
|
||||
setTransactionTime = true;
|
||||
newTransactionTime = startTime.value;
|
||||
}
|
||||
|
||||
@@ -466,8 +463,6 @@ function updateClosingBalance(): void {
|
||||
type: newTransactionType,
|
||||
amount: newTransactionAmount,
|
||||
accountId: accountId.value,
|
||||
setAmount: true,
|
||||
setTransactionTime: setTransactionTime,
|
||||
noTransactionDraft: true
|
||||
}).then(result => {
|
||||
if (result && result.message) {
|
||||
|
||||
@@ -1580,15 +1580,12 @@ function changeAmountFilter(filterType: string): void {
|
||||
function add(template?: TransactionTemplate): void {
|
||||
const currentUnixTime = getCurrentUnixTime();
|
||||
|
||||
let setTransactionTime = false;
|
||||
let newTransactionTime: number | undefined = undefined;
|
||||
|
||||
if (query.value.maxTime && query.value.minTime) {
|
||||
if (query.value.maxTime < currentUnixTime) {
|
||||
setTransactionTime = true;
|
||||
newTransactionTime = query.value.maxTime;
|
||||
} else if (currentUnixTime < query.value.minTime) {
|
||||
setTransactionTime = true;
|
||||
newTransactionTime = query.value.minTime;
|
||||
}
|
||||
}
|
||||
@@ -1599,8 +1596,7 @@ function add(template?: TransactionTemplate): void {
|
||||
categoryId: queryAllFilterCategoryIdsCount.value === 1 ? query.value.categoryIds : '',
|
||||
accountId: queryAllFilterAccountIdsCount.value === 1 ? query.value.accountIds : '',
|
||||
tagIds: query.value.tagIds || '',
|
||||
template: template,
|
||||
setTransactionTime: setTransactionTime
|
||||
template: template
|
||||
}).then(result => {
|
||||
if (result && result.message) {
|
||||
snackbar.value?.showMessage(result.message);
|
||||
|
||||
@@ -497,7 +497,6 @@ import { TransactionTemplate } from '@/models/transaction_template.ts';
|
||||
import type { TransactionPictureInfoBasicResponse } from '@/models/transaction_picture_info.ts';
|
||||
import { Transaction } from '@/models/transaction.ts';
|
||||
|
||||
import { isDefined } from '@/lib/common.ts';
|
||||
import {
|
||||
getTimezoneOffsetMinutes,
|
||||
getCurrentUnixTime
|
||||
@@ -538,9 +537,6 @@ export interface TransactionEditOptions extends SetTransactionOptions {
|
||||
template?: TransactionTemplate;
|
||||
currentTransaction?: Transaction;
|
||||
currentTemplate?: TransactionTemplate;
|
||||
time?: number;
|
||||
setAmount?: boolean;
|
||||
setTransactionTime?: boolean;
|
||||
noTransactionDraft?: boolean;
|
||||
}
|
||||
|
||||
@@ -688,6 +684,7 @@ function setTransaction(newTransaction: Transaction | null, options: SetTransact
|
||||
allTagsMap.value,
|
||||
defaultAccountId.value,
|
||||
{
|
||||
time: options.time,
|
||||
type: options.type,
|
||||
categoryId: options.categoryId,
|
||||
accountId: options.accountId,
|
||||
@@ -714,10 +711,7 @@ function open(options: TransactionEditOptions): Promise<TransactionEditResponse
|
||||
originalTransactionEditable.value = false;
|
||||
noTransactionDraft.value = options.noTransactionDraft || false;
|
||||
|
||||
if (options.setAmount) {
|
||||
initAmount.value = options.amount;
|
||||
}
|
||||
|
||||
initAmount.value = options.amount;
|
||||
initCategoryId.value = options.categoryId;
|
||||
initAccountId.value = options.accountId;
|
||||
initTagIds.value = options.tagIds;
|
||||
@@ -828,14 +822,6 @@ function open(options: TransactionEditOptions): Promise<TransactionEditResponse
|
||||
(transaction.value as TransactionTemplate).fillFrom(template);
|
||||
} else {
|
||||
setTransaction(null, options, true, true);
|
||||
|
||||
if (options.setAmount && isDefined(options.amount)) {
|
||||
transaction.value.sourceAmount = options.amount;
|
||||
}
|
||||
|
||||
if (options.setTransactionTime && isDefined(options.time)) {
|
||||
transaction.value.time = options.time;
|
||||
}
|
||||
}
|
||||
|
||||
loading.value = false;
|
||||
|
||||
@@ -544,12 +544,10 @@ function updateClosingBalance(balance?: number): void {
|
||||
|
||||
if (setTransactionTime) {
|
||||
params.push(`time=${newTransactionTime}`);
|
||||
params.push('withTime=true');
|
||||
}
|
||||
|
||||
params.push(`type=${newTransactionType}`);
|
||||
params.push(`amount=${newTransactionAmount}`);
|
||||
params.push(`withAmount=true`);
|
||||
params.push(`accountId=${accountId.value}`);
|
||||
params.push(`noTransactionDraft=true`);
|
||||
|
||||
|
||||
@@ -509,7 +509,6 @@ import { TransactionTemplate } from '@/models/transaction_template.ts';
|
||||
import type { TransactionPictureInfoBasicResponse } from '@/models/transaction_picture_info.ts';
|
||||
import { Transaction } from '@/models/transaction.ts';
|
||||
|
||||
import { isDefined } from '@/lib/common.ts';
|
||||
import {
|
||||
getActualUnixTimeForStore,
|
||||
getBrowserTimezoneOffsetMinutes,
|
||||
@@ -931,6 +930,7 @@ function init(): void {
|
||||
allTagsMap.value,
|
||||
defaultAccountId.value,
|
||||
{
|
||||
time: query['time'] ? parseInt(query['time']) : undefined,
|
||||
type: queryType,
|
||||
categoryId: query['categoryId'],
|
||||
accountId: query['accountId'],
|
||||
@@ -963,14 +963,6 @@ function init(): void {
|
||||
}
|
||||
|
||||
(transaction.value as TransactionTemplate).fillFrom(template);
|
||||
} else {
|
||||
if (query['withAmount'] && query['withAmount'] === 'true' && isDefined(query['amount']) && parseInt(query['amount'])) {
|
||||
transaction.value.sourceAmount = parseInt(query['amount']);
|
||||
}
|
||||
|
||||
if (query['withTime'] && query['withTime'] === 'true' && isDefined(query['time']) && parseInt(query['time'])) {
|
||||
transaction.value.time = parseInt(query['time']);
|
||||
}
|
||||
}
|
||||
|
||||
loading.value = false;
|
||||
@@ -1234,7 +1226,7 @@ function onPageBeforeOut(): void {
|
||||
return;
|
||||
}
|
||||
|
||||
const initAmount: number | undefined = query['withAmount'] && query['withAmount'] === 'true' && query['amount'] ? parseInt(query['amount']) : undefined;
|
||||
const initAmount: number | undefined = query['amount'] ? parseInt(query['amount']) : undefined;
|
||||
|
||||
if (settingsStore.appSettings.autoSaveTransactionDraft === 'confirmation') {
|
||||
if (transactionsStore.isTransactionDraftModified(transaction.value, initAmount, query['categoryId'], query['accountId'], query['tagIds'])) {
|
||||
|
||||
@@ -1394,7 +1394,6 @@ function add(): void {
|
||||
|
||||
if (setTransactionTime) {
|
||||
params.push(`time=${newTransactionTime}`);
|
||||
params.push('withTime=true');
|
||||
}
|
||||
|
||||
if (query.value.type !== TransactionType.ModifyBalance) {
|
||||
|
||||
Reference in New Issue
Block a user