mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-14 06:57:35 +08:00
disable transaction draft when update closing balance
This commit is contained in:
@@ -474,12 +474,12 @@ export const useTransactionsStore = defineStore('transactions', () => {
|
||||
}
|
||||
}
|
||||
|
||||
function isTransactionDraftModified(transaction?: Transaction, initCategoryId?: string, initAccountId?: string, initTagIds?: string): boolean {
|
||||
function isTransactionDraftModified(transaction?: Transaction, initAmount?: number, initCategoryId?: string, initAccountId?: string, initTagIds?: string): boolean {
|
||||
if (!transaction) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (transaction.sourceAmount !== 0) {
|
||||
if (transaction.sourceAmount !== 0 && transaction.sourceAmount !== initAmount) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -538,14 +538,14 @@ export const useTransactionsStore = defineStore('transactions', () => {
|
||||
return false;
|
||||
}
|
||||
|
||||
function saveTransactionDraft(transaction?: Transaction, initCategoryId?: string, initAccountId?: string, initTagIds?: string): void {
|
||||
function saveTransactionDraft(transaction?: Transaction, initAmount?: number, initCategoryId?: string, initAccountId?: string, initTagIds?: string): void {
|
||||
if (settingsStore.appSettings.autoSaveTransactionDraft !== 'enabled' && settingsStore.appSettings.autoSaveTransactionDraft !== 'confirmation') {
|
||||
clearTransactionDraft();
|
||||
return;
|
||||
}
|
||||
|
||||
if (transaction) {
|
||||
if (!isTransactionDraftModified(transaction, initCategoryId, initAccountId, initTagIds)) {
|
||||
if (!isTransactionDraftModified(transaction, initAmount, initCategoryId, initAccountId, initTagIds)) {
|
||||
clearTransactionDraft();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -467,7 +467,8 @@ function updateClosingBalance(): void {
|
||||
amount: newTransactionAmount,
|
||||
accountId: accountId.value,
|
||||
setAmount: true,
|
||||
setTransactionTime: setTransactionTime
|
||||
setTransactionTime: setTransactionTime,
|
||||
noTransactionDraft: true
|
||||
}).then(result => {
|
||||
if (result && result.message) {
|
||||
snackbar.value?.showMessage(result.message);
|
||||
|
||||
@@ -541,6 +541,7 @@ export interface TransactionEditOptions extends SetTransactionOptions {
|
||||
time?: number;
|
||||
setAmount?: boolean;
|
||||
setTransactionTime?: boolean;
|
||||
noTransactionDraft?: boolean;
|
||||
}
|
||||
|
||||
interface TransactionEditResponse {
|
||||
@@ -624,10 +625,12 @@ const pictureInput = useTemplateRef<HTMLInputElement>('pictureInput');
|
||||
const showState = ref<boolean>(false);
|
||||
const activeTab = ref<string>('basicInfo');
|
||||
const originalTransactionEditable = ref<boolean>(false);
|
||||
const noTransactionDraft = ref<boolean>(false);
|
||||
const geoMenuState = ref<boolean>(false);
|
||||
const tagSearchContent = ref<string>('');
|
||||
const removingPictureId = ref<string>('');
|
||||
|
||||
const initAmount = ref<number | undefined>(undefined);
|
||||
const initCategoryId = ref<string | undefined>(undefined);
|
||||
const initAccountId = ref<string | undefined>(undefined);
|
||||
const initTagIds = ref<string | undefined>(undefined);
|
||||
@@ -666,7 +669,7 @@ const isAllFilteredTagHidden = computed<boolean>(() => {
|
||||
|
||||
const isTransactionModified = computed<boolean>(() => {
|
||||
if (mode.value === TransactionEditPageMode.Add) {
|
||||
return transactionsStore.isTransactionDraftModified(transaction.value, initCategoryId.value, initAccountId.value, initTagIds.value);
|
||||
return transactionsStore.isTransactionDraftModified(transaction.value, initAmount.value, initCategoryId.value, initAccountId.value, initTagIds.value);
|
||||
} else if (mode.value === TransactionEditPageMode.Edit) {
|
||||
return true;
|
||||
} else {
|
||||
@@ -709,6 +712,11 @@ function open(options: TransactionEditOptions): Promise<TransactionEditResponse
|
||||
geoLocationStatus.value = null;
|
||||
setGeoLocationByClickMap.value = false;
|
||||
originalTransactionEditable.value = false;
|
||||
noTransactionDraft.value = options.noTransactionDraft || false;
|
||||
|
||||
if (options.setAmount) {
|
||||
initAmount.value = options.amount;
|
||||
}
|
||||
|
||||
initCategoryId.value = options.categoryId;
|
||||
initAccountId.value = options.accountId;
|
||||
@@ -740,7 +748,7 @@ function open(options: TransactionEditOptions): Promise<TransactionEditResponse
|
||||
if (options.template) {
|
||||
setTransaction(options.template, options, false, false);
|
||||
addByTemplateId.value = options.template.id;
|
||||
} else if ((settingsStore.appSettings.autoSaveTransactionDraft === 'enabled' || settingsStore.appSettings.autoSaveTransactionDraft === 'confirmation') && transactionsStore.transactionDraft) {
|
||||
} else if (!options.noTransactionDraft && (settingsStore.appSettings.autoSaveTransactionDraft === 'enabled' || settingsStore.appSettings.autoSaveTransactionDraft === 'confirmation') && transactionsStore.transactionDraft) {
|
||||
setTransaction(Transaction.ofDraft(transactionsStore.transactionDraft), options, false, false);
|
||||
}
|
||||
|
||||
@@ -882,7 +890,7 @@ function save(): void {
|
||||
}
|
||||
}
|
||||
|
||||
if (mode.value === TransactionEditPageMode.Add && !addByTemplateId.value && !duplicateFromId.value) {
|
||||
if (mode.value === TransactionEditPageMode.Add && !noTransactionDraft.value && !addByTemplateId.value && !duplicateFromId.value) {
|
||||
transactionsStore.clearTransactionDraft();
|
||||
}
|
||||
|
||||
@@ -1024,15 +1032,15 @@ function cancel(): void {
|
||||
showState.value = false;
|
||||
};
|
||||
|
||||
if (props.type !== TransactionEditPageType.Transaction || mode.value !== TransactionEditPageMode.Add || addByTemplateId.value || duplicateFromId.value) {
|
||||
if (props.type !== TransactionEditPageType.Transaction || mode.value !== TransactionEditPageMode.Add || noTransactionDraft.value || addByTemplateId.value || duplicateFromId.value) {
|
||||
doClose();
|
||||
return;
|
||||
}
|
||||
|
||||
if (settingsStore.appSettings.autoSaveTransactionDraft === 'confirmation') {
|
||||
if (transactionsStore.isTransactionDraftModified(transaction.value, initCategoryId.value, initAccountId.value, initTagIds.value)) {
|
||||
if (transactionsStore.isTransactionDraftModified(transaction.value, initAmount.value, initCategoryId.value, initAccountId.value, initTagIds.value)) {
|
||||
confirmDialog.value?.open('Do you want to save this transaction draft?').then(() => {
|
||||
transactionsStore.saveTransactionDraft(transaction.value, initCategoryId.value, initAccountId.value, initTagIds.value);
|
||||
transactionsStore.saveTransactionDraft(transaction.value, initAmount.value, initCategoryId.value, initAccountId.value, initTagIds.value);
|
||||
doClose();
|
||||
}).catch(() => {
|
||||
transactionsStore.clearTransactionDraft();
|
||||
@@ -1043,7 +1051,7 @@ function cancel(): void {
|
||||
doClose();
|
||||
}
|
||||
} else if (settingsStore.appSettings.autoSaveTransactionDraft === 'enabled') {
|
||||
transactionsStore.saveTransactionDraft(transaction.value, initCategoryId.value, initAccountId.value, initTagIds.value);
|
||||
transactionsStore.saveTransactionDraft(transaction.value, initAmount.value, initCategoryId.value, initAccountId.value, initTagIds.value);
|
||||
doClose();
|
||||
} else {
|
||||
doClose();
|
||||
|
||||
@@ -540,11 +540,20 @@ function updateClosingBalance(balance?: number): void {
|
||||
newTransactionAmount = -newTransactionAmount;
|
||||
}
|
||||
|
||||
const params: string[] = [];
|
||||
|
||||
if (setTransactionTime) {
|
||||
props.f7router.navigate(`/transaction/add?time=${newTransactionTime}&type=${newTransactionType}&amount=${newTransactionAmount}&accountId=${accountId.value}&withAmount=true&withTime=true`);
|
||||
} else {
|
||||
props.f7router.navigate(`/transaction/add?type=${newTransactionType}&amount=${newTransactionAmount}&accountId=${accountId.value}&withAmount=true`);
|
||||
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`);
|
||||
|
||||
props.f7router.navigate(`/transaction/add?${params.join('&')}`);
|
||||
}
|
||||
|
||||
function removeTransaction(transaction: TransactionReconciliationStatementResponseItem | null, confirm: boolean): void {
|
||||
|
||||
@@ -912,7 +912,7 @@ function init(): void {
|
||||
if (fromTransaction) {
|
||||
addByTemplateId.value = fromTransaction.id;
|
||||
}
|
||||
} else if ((settingsStore.appSettings.autoSaveTransactionDraft === 'enabled' || settingsStore.appSettings.autoSaveTransactionDraft === 'confirmation') && transactionsStore.transactionDraft) {
|
||||
} else if (query['noTransactionDraft'] !== 'true' && (settingsStore.appSettings.autoSaveTransactionDraft === 'enabled' || settingsStore.appSettings.autoSaveTransactionDraft === 'confirmation') && transactionsStore.transactionDraft) {
|
||||
fromTransaction = Transaction.ofDraft(transactionsStore.transactionDraft);
|
||||
}
|
||||
} else if (pageTypeAndMode.type === TransactionEditPageType.Template && responses[4] instanceof TransactionTemplate) {
|
||||
@@ -1020,7 +1020,7 @@ function save(): void {
|
||||
showToast('You have saved this transaction');
|
||||
}
|
||||
|
||||
if (mode.value === TransactionEditPageMode.Add && !addByTemplateId.value && !duplicateFromId.value) {
|
||||
if (mode.value === TransactionEditPageMode.Add && query['noTransactionDraft'] !== 'true' && !addByTemplateId.value && !duplicateFromId.value) {
|
||||
transactionsStore.clearTransactionDraft();
|
||||
}
|
||||
|
||||
@@ -1230,14 +1230,16 @@ function onPageAfterIn(): void {
|
||||
}
|
||||
|
||||
function onPageBeforeOut(): void {
|
||||
if (submitted.value || pageTypeAndMode?.type !== TransactionEditPageType.Transaction || mode.value !== TransactionEditPageMode.Add || addByTemplateId.value || duplicateFromId.value) {
|
||||
if (submitted.value || pageTypeAndMode?.type !== TransactionEditPageType.Transaction || mode.value !== TransactionEditPageMode.Add || query['noTransactionDraft'] === 'true' || addByTemplateId.value || duplicateFromId.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
const initAmount: number | undefined = query['withAmount'] && query['withAmount'] === 'true' && query['amount'] ? parseInt(query['amount']) : undefined;
|
||||
|
||||
if (settingsStore.appSettings.autoSaveTransactionDraft === 'confirmation') {
|
||||
if (transactionsStore.isTransactionDraftModified(transaction.value, query['categoryId'], query['accountId'], query['tagIds'])) {
|
||||
if (transactionsStore.isTransactionDraftModified(transaction.value, initAmount, query['categoryId'], query['accountId'], query['tagIds'])) {
|
||||
showConfirm('Do you want to save this transaction draft?', () => {
|
||||
transactionsStore.saveTransactionDraft(transaction.value, query['categoryId'], query['accountId'], query['tagIds']);
|
||||
transactionsStore.saveTransactionDraft(transaction.value, initAmount, query['categoryId'], query['accountId'], query['tagIds']);
|
||||
}, () => {
|
||||
transactionsStore.clearTransactionDraft();
|
||||
});
|
||||
@@ -1245,7 +1247,7 @@ function onPageBeforeOut(): void {
|
||||
transactionsStore.clearTransactionDraft();
|
||||
}
|
||||
} else if (settingsStore.appSettings.autoSaveTransactionDraft === 'enabled') {
|
||||
transactionsStore.saveTransactionDraft(transaction.value, query['categoryId'], query['accountId'], query['tagIds']);
|
||||
transactionsStore.saveTransactionDraft(transaction.value, initAmount, query['categoryId'], query['accountId'], query['tagIds']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user