WIP: Add Drafts, Templates, and Recurring Transactions #45
|
|
@ -59,6 +59,13 @@ export interface Account {
|
|||
currentBalance: number | null
|
||||
}
|
||||
|
||||
export interface SimpleAccountResponse {
|
||||
id: number
|
||||
name: string
|
||||
type: string
|
||||
numberSuffix: string
|
||||
}
|
||||
|
||||
export interface AccountCreationPayload {
|
||||
type: string
|
||||
numberSuffix: string
|
||||
|
|
|
|||
|
|
@ -1,8 +1,28 @@
|
|||
import type { SimpleAccountResponse } from './account'
|
||||
import type { Attachment } from './attachment'
|
||||
import { ApiClient } from './base'
|
||||
import type { Currency } from './data'
|
||||
import { type Page, type PageRequest } from './pagination'
|
||||
|
||||
export interface SimpleVendorResponse {
|
||||
id: number
|
||||
name: string
|
||||
}
|
||||
|
||||
export interface SimpleCategoryResponse {
|
||||
id: number
|
||||
name: string
|
||||
color: string
|
||||
}
|
||||
|
||||
export interface TransactionLineItemResponse {
|
||||
idx: number
|
||||
valuePerItem: number
|
||||
quantity: number
|
||||
description: string
|
||||
category: TransactionCategory | null
|
||||
}
|
||||
|
||||
export interface TransactionVendor {
|
||||
id: number
|
||||
name: string
|
||||
|
|
@ -47,10 +67,10 @@ export interface TransactionsListItem {
|
|||
currency: Currency
|
||||
description: string
|
||||
internalTransfer: boolean
|
||||
vendor: TransactionsListItemVendor | null
|
||||
category: TransactionsListItemCategory | null
|
||||
creditedAccount: TransactionsListItemAccount | null
|
||||
debitedAccount: TransactionsListItemAccount | null
|
||||
vendor: SimpleVendorResponse | null
|
||||
category: SimpleCategoryResponse | null
|
||||
creditedAccount: SimpleAccountResponse | null
|
||||
debitedAccount: SimpleAccountResponse | null
|
||||
tags: string[]
|
||||
}
|
||||
|
||||
|
|
@ -82,28 +102,13 @@ export interface TransactionDetail {
|
|||
internalTransfer: boolean
|
||||
vendor: TransactionVendor | null
|
||||
category: TransactionCategory | null
|
||||
creditedAccount: TransactionDetailAccount | null
|
||||
debitedAccount: TransactionDetailAccount | null
|
||||
creditedAccount: SimpleAccountResponse | null
|
||||
debitedAccount: SimpleAccountResponse | null
|
||||
tags: string[]
|
||||
lineItems: TransactionDetailLineItem[]
|
||||
lineItems: TransactionLineItemResponse[]
|
||||
attachments: Attachment[]
|
||||
}
|
||||
|
||||
export interface TransactionDetailAccount {
|
||||
id: number
|
||||
name: string
|
||||
type: string
|
||||
numberSuffix: string
|
||||
}
|
||||
|
||||
export interface TransactionDetailLineItem {
|
||||
idx: number
|
||||
valuePerItem: number
|
||||
quantity: number
|
||||
description: string
|
||||
category: TransactionCategory | null
|
||||
}
|
||||
|
||||
export interface AddTransactionPayload {
|
||||
timestamp: string
|
||||
amount: number
|
||||
|
|
@ -144,6 +149,56 @@ export interface AggregateTransactionData {
|
|||
currencies: AggregateTransactionCurrencyData[]
|
||||
}
|
||||
|
||||
export interface TransactionDraftListItem {
|
||||
id: number
|
||||
addedAt: string
|
||||
templateName: string | null
|
||||
timestamp: string | null
|
||||
amount: number | null
|
||||
currency: Currency | null
|
||||
description: string | null
|
||||
internalTransfer: boolean | null
|
||||
vendor: SimpleVendorResponse | null
|
||||
category: SimpleCategoryResponse | null
|
||||
creditedAccount: SimpleAccountResponse | null
|
||||
debitedAccount: SimpleAccountResponse | null
|
||||
tags: string[]
|
||||
}
|
||||
|
||||
export interface TransactionDraftResponse {
|
||||
id: number
|
||||
addedAt: string
|
||||
templateName: string | null
|
||||
timestamp: string | null
|
||||
amount: number | null
|
||||
currency: Currency | null
|
||||
description: string | null
|
||||
internalTransfer: boolean | null
|
||||
vendor: SimpleVendorResponse | null
|
||||
category: SimpleCategoryResponse | null
|
||||
creditedAccount: SimpleAccountResponse | null
|
||||
debitedAccount: SimpleAccountResponse | null
|
||||
tags: string[]
|
||||
lineItems: TransactionLineItemResponse[]
|
||||
attachments: Attachment[]
|
||||
}
|
||||
|
||||
export interface TransactionDraftPayload {
|
||||
templateName: string | null
|
||||
timestamp: string | null
|
||||
amount: number | null
|
||||
currencyCode: string | null
|
||||
description: string | null
|
||||
internalTransfer: boolean | null
|
||||
vendorId: number | null
|
||||
categoryId: number | null
|
||||
creditedAccountId: number | null
|
||||
debitedAccountId: number | null
|
||||
tags: string[]
|
||||
lineItems: AddTransactionPayloadLineItem[]
|
||||
attachmentIdsToRemove: number[]
|
||||
}
|
||||
|
||||
export class TransactionApiClient extends ApiClient {
|
||||
readonly path: string
|
||||
|
||||
|
|
@ -277,4 +332,57 @@ export class TransactionApiClient extends ApiClient {
|
|||
getAllTags(): Promise<string[]> {
|
||||
return super.getJson(this.path + '/transaction-tags')
|
||||
}
|
||||
|
||||
// Drafts:
|
||||
|
||||
getDrafts(
|
||||
paginationOptions: PageRequest | undefined = undefined,
|
||||
): Promise<Page<TransactionDraftListItem>> {
|
||||
return super.getJsonPage(this.path + '/transaction-drafts', paginationOptions)
|
||||
}
|
||||
|
||||
getTemplateDrafts(
|
||||
paginationOptions: PageRequest | undefined = undefined,
|
||||
): Promise<Page<TransactionDraftListItem>> {
|
||||
const params = new URLSearchParams()
|
||||
params.append('template', 'true')
|
||||
if (paginationOptions !== undefined) {
|
||||
params.append('page', paginationOptions.page + '')
|
||||
params.append('size', paginationOptions.size + '')
|
||||
for (const sort of paginationOptions.sorts) {
|
||||
params.append('sort', sort.attribute + ',' + sort.dir)
|
||||
}
|
||||
}
|
||||
return super.getJson(this.path + '/transaction-drafts?' + params.toString())
|
||||
}
|
||||
|
||||
getDraft(id: number): Promise<TransactionDraftResponse> {
|
||||
return super.getJson(this.path + '/transaction-drafts/' + id)
|
||||
}
|
||||
|
||||
addDraft(data: TransactionDraftPayload, files: File[] = []): Promise<TransactionDraftResponse> {
|
||||
const formData = new FormData()
|
||||
formData.append('payload', JSON.stringify(data))
|
||||
for (const file of files) {
|
||||
formData.append('file', file)
|
||||
}
|
||||
return super.postFormData(this.path + '/transaction-drafts', formData)
|
||||
}
|
||||
|
||||
updateDraft(
|
||||
id: number,
|
||||
data: TransactionDraftPayload,
|
||||
files: File[] = [],
|
||||
): Promise<TransactionDraftResponse> {
|
||||
const formData = new FormData()
|
||||
formData.append('payload', JSON.stringify(data))
|
||||
for (const file of files) {
|
||||
formData.append('file', file)
|
||||
}
|
||||
return super.putFormData(this.path + '/transaction-drafts/' + id, formData)
|
||||
}
|
||||
|
||||
deleteDraft(id: number): Promise<void> {
|
||||
return super.delete(this.path + '/transaction-drafts/' + id)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
<script setup lang="ts">
|
||||
import type { TransactionDetailLineItem } from '@/api/transaction'
|
||||
import type { TransactionLineItemResponse } from '@/api/transaction'
|
||||
import AppButton from './common/AppButton.vue'
|
||||
import { formatMoney, type Currency } from '@/api/data'
|
||||
|
||||
defineProps<{
|
||||
lineItem: TransactionDetailLineItem
|
||||
lineItem: TransactionLineItemResponse
|
||||
currency: Currency
|
||||
totalCount?: number
|
||||
editable?: boolean
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ transaction. This editor shows a table of current line items, and includes a
|
|||
modal for adding a new one.
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { type TransactionCategoryTree, type TransactionDetailLineItem } from '@/api/transaction'
|
||||
import { type TransactionCategoryTree, type TransactionLineItemResponse } from '@/api/transaction'
|
||||
import AppButton from '@/components/common/AppButton.vue'
|
||||
import FormGroup from '@/components/common/form/FormGroup.vue'
|
||||
import { floatMoneyToInteger, formatMoney, type Currency } from '@/api/data'
|
||||
|
|
@ -15,7 +15,7 @@ import CategorySelect from './CategorySelect.vue'
|
|||
import LineItemCard from './LineItemCard.vue'
|
||||
import AppBadge from './common/AppBadge.vue'
|
||||
|
||||
const model = defineModel<TransactionDetailLineItem[]>({ required: true })
|
||||
const model = defineModel<TransactionLineItemResponse[]>({ required: true })
|
||||
const props = defineProps<{
|
||||
transactionAmount: number
|
||||
currency: Currency
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import {
|
|||
TransactionApiClient,
|
||||
type AddTransactionPayload,
|
||||
type TransactionDetail,
|
||||
type TransactionDetailLineItem,
|
||||
type TransactionLineItemResponse,
|
||||
type TransactionVendor,
|
||||
} from '@/api/transaction'
|
||||
import AppPage from '@/components/common/AppPage.vue'
|
||||
|
|
@ -144,7 +144,7 @@ const vendor: Ref<TransactionVendor | null> = ref(null)
|
|||
const categoryId: Ref<number | null> = ref(null)
|
||||
const creditedAccountId: Ref<number | null> = ref(null)
|
||||
const debitedAccountId: Ref<number | null> = ref(null)
|
||||
const lineItems: Ref<TransactionDetailLineItem[]> = ref([])
|
||||
const lineItems: Ref<TransactionLineItemResponse[]> = ref([])
|
||||
const tags: Ref<string[]> = ref([])
|
||||
const customTagInput = ref('')
|
||||
const customTagInputValid = ref(false)
|
||||
|
|
|
|||
Loading…
Reference in New Issue