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