Skip to content

TaskView is a self-hosted project and task management platform focused on clarity, ownership, and control. TaskView is built for teams that want a transparent, self-hosted alternative to SaaS task managers.

fix: invoice ui

Nikolai Gimand1f39fc2e3b0
diff --git a/api/src/tv-modules/invoices/InvoicesManager.ts b/api/src/tv-modules/invoices/InvoicesManager.ts
index 03b2ac3..7c5f235 100644
--- a/api/src/tv-modules/invoices/InvoicesManager.ts
+++ b/api/src/tv-modules/invoices/InvoicesManager.ts
@@ -12,6 +12,7 @@ import { InvoicesRepository } from './InvoicesRepository'
import {
INVOICE_TEMPLATE_VERSION,
INVOICE_TRANSITIONS,
+ type InvoiceArgCreate,
type InvoiceArgList,
type InvoiceArgUpdate,
type InvoiceCreateArgs,
@@ -105,39 +106,41 @@ export class InvoicesManager {
}
const number = await this.repository.nextNumber({ organizationId: original.organizationId, base: original.number })
+ const data: InvoiceArgCreate = {
+ organizationId: original.organizationId,
+ goalId: original.goalId,
+ sellerId: original.sellerId,
+ counterpartyId: original.counterpartyId,
+ number,
+ reference: original.reference,
+ currencyCode: original.currencyCode,
+ issueDate: new Date().toISOString().slice(0, 10),
+ paymentTerms: original.paymentTerms,
+ dueDate: original.dueDate,
+ periodFrom: original.periodFrom,
+ periodTo: original.periodTo,
+ discountType: original.discountType,
+ discountValue: Number(original.discountValue),
+ taxRate: Number(original.taxRate),
+ taxExempt: original.taxExempt,
+ taxNote: original.taxNote,
+ notes: original.notes,
+ terms: original.terms,
+ lines: original.lines.map((line) => ({
+ taskId: line.taskId,
+ description: line.description,
+ unit: line.unit,
+ quantity: Number(line.quantity),
+ unitPrice: Number(line.unitPrice),
+ })),
+ }
+ const snapshots = await this.resolveSnapshots(original.organizationId, data)
const created = await this.repository.create({
createdBy,
- sellerSnapshot: original.sellerSnapshot,
- counterpartySnapshot: original.counterpartySnapshot,
- goalName: original.goalName,
- data: {
- organizationId: original.organizationId,
- goalId: original.goalId,
- sellerId: original.sellerId,
- counterpartyId: original.counterpartyId,
- number,
- reference: original.reference,
- currencyCode: original.currencyCode,
- issueDate: new Date().toISOString().slice(0, 10),
- paymentTerms: original.paymentTerms,
- dueDate: original.dueDate,
- periodFrom: original.periodFrom,
- periodTo: original.periodTo,
- discountType: original.discountType,
- discountValue: Number(original.discountValue),
- taxRate: Number(original.taxRate),
- taxExempt: original.taxExempt,
- taxNote: original.taxNote,
- notes: original.notes,
- terms: original.terms,
- lines: original.lines.map((line) => ({
- taskId: line.taskId,
- description: line.description,
- unit: line.unit,
- quantity: Number(line.quantity),
- unitPrice: Number(line.unitPrice),
- })),
- },
+ data,
+ ...(typeof snapshots === 'string'
+ ? { sellerSnapshot: original.sellerSnapshot, counterpartySnapshot: original.counterpartySnapshot, goalName: original.goalName }
+ : snapshots),
})
if (!created || created === 'duplicate_number') return { error: 'not_found' }
await this.repository.setReplaces({ invoiceId: created.id, replacesInvoiceId: original.id })
diff --git a/taskview-packages/taskview-api/src/api/__tests__/billing-invoices.test.ts b/taskview-packages/taskview-api/src/api/__tests__/billing-invoices.test.ts
new file mode 100644
index 0000000..7ec6c19
--- /dev/null
+++ b/taskview-packages/taskview-api/src/api/__tests__/billing-invoices.test.ts
@@ -0,0 +1,468 @@
+import { TvApi } from '@/tv'
+import type { CounterpartyArgCreate, InvoiceArgCreate, SellerArgCreate } from '@/index'
+import { describe, it, expect, beforeAll, afterAll } from 'vitest'
+import axios, { type AxiosInstance } from 'axios'
+import { initApi, API_URL, DEFAULT_USER, DEFAULT_USER_2, DEFAULT_PASSWORD } from './init-api'
+import { ymd } from './test-helpers'
+
+/**
+ * Billing (currencies, sellers, clients) and invoices end to end.
+ *
+ * `owner` (user1) owns organization A, `member` (user2) is a plain member of A
+ * and the owner of organization B. Billing is an owner/admin surface, so the
+ * member must be refused everywhere, and nobody may reach another
+ * organization's records by id. The invoice lifecycle is checked transition by
+ * transition: only the moves from the status matrix succeed, issuing freezes
+ * the totals, editing stops after issue, and "correct" voids the original and
+ * opens a replacement draft.
+ */
+describe('Billing and invoices', () => {
+ let owner: TvApi
+ let member: TvApi
+ let ownerRaw: AxiosInstance
+ let memberRaw: AxiosInstance
+ let memberEmail: string
+ let deleteAllGoals: () => Promise<void>
+
+ let orgA = 0
+ let orgB = 0
+ let goalId = 0
+ let sellerId = 0
+ let counterpartyId = 0
+ let foreignSellerId = 0
+ let invoiceId = 0
+
+ const rawClient = async (login: string) => {
+ const auth = await axios.post(`${API_URL}/module/auth/login`, { login, password: DEFAULT_PASSWORD })
+ return axios.create({
+ baseURL: API_URL,
+ headers: { Authorization: `Bearer ${auth.data.access}` },
+ validateStatus: () => true,
+ })
+ }
+
+ const sellerPayload = (organizationId: number): SellerArgCreate => ({
+ organizationId,
+ name: 'E2E Seller',
+ legalName: 'E2E Seller LLC',
+ address: '',
+ email: '[email protected]',
+ phone: '',
+ logoUrl: '',
+ currencyCode: 'EUR',
+ bank: { bankName: 'Bank', accountNumber: '', iban: '', swift: '', correspondentAccount: '' },
+ requisites: [{ key: 'vat', label: 'VAT ID', value: 'DE000' }],
+ defaultTerms: 'Net 14',
+ taxNote: 'VAT not applicable',
+ })
+
+ const counterpartyPayload = (organizationId: number): CounterpartyArgCreate => ({
+ organizationId,
+ kind: 'organization',
+ name: 'E2E Client',
+ legalName: 'E2E Client GmbH',
+ address: '',
+ email: '[email protected]',
+ phone: '',
+ contactPerson: 'Anna',
+ requisites: [],
+ })
+
+ const invoicePayload = (number: string): InvoiceArgCreate => ({
+ organizationId: orgA,
+ goalId,
+ sellerId,
+ counterpartyId,
+ number,
+ reference: 'PO-1',
+ currencyCode: 'EUR',
+ issueDate: ymd(0),
+ paymentTerms: 'net14',
+ dueDate: ymd(14),
+ periodFrom: null,
+ periodTo: null,
+ discountType: 'percent',
+ discountValue: 10,
+ taxRate: 19,
+ taxExempt: false,
+ taxNote: '',
+ notes: '',
+ terms: 'Net 14',
+ lines: [
+ { taskId: null, description: 'Design', unit: 'service', quantity: 1, unitPrice: 1000 },
+ { taskId: null, description: 'Development', unit: 'hours', quantity: 10.5, unitPrice: 80 },
+ ],
+ })
+
+ beforeAll(async () => {
+ const init = await initApi()
+ owner = init.$tvApi
+ member = init.$tvApiForSecondUser
+ memberEmail = init.user2Email
+ deleteAllGoals = init.deleteAllGoals
+ ownerRaw = await rawClient(DEFAULT_USER)
+ memberRaw = await rawClient(DEFAULT_USER_2)
+
+ const a = await owner.organizations.create({ name: `billing-e2e-A-${Date.now()}` })
+ if (!a) throw new Error('Failed to create organization A')
+ orgA = a.id
+ await owner.organizations.addMember({ organizationId: orgA, email: memberEmail, role: 'member' })
+
+ const b = await member.organizations.create({ name: `billing-e2e-B-${Date.now()}` })
+ if (!b) throw new Error('Failed to create organization B')
+ orgB = b.id
+
+ const goal = await owner.goals.createGoal({ name: 'billing-e2e-goal', organizationId: orgA })
+ if (!goal) throw new Error('Failed to create goal')
+ goalId = goal.id!
+ })
+
+ afterAll(async () => {
+ await deleteAllGoals()
+ if (orgA) await owner.organizations.delete(orgA).catch(() => null)
+ if (orgB) await member.organizations.delete(orgB).catch(() => null)
+ })
+
+ describe('currencies', () => {
+ it('lists the seeded currencies for any logged-in user', async () => {
+ const currencies = await member.billing.fetchCurrencies()
+ expect(currencies.length).toBeGreaterThanOrEqual(20)
+ const jpy = currencies.find((c) => c.code.trim() === 'JPY')
+ expect(jpy?.decimalDigits).toBe(0)
+ expect(currencies.find((c) => c.code.trim() === 'USD')?.symbol).toBe('$')
+ })
+
+ it('refuses anonymous access', async () => {
+ const response = await axios.get(`${API_URL}/module/billing/currencies`, { validateStatus: () => true })
+ expect(response.status).toBe(401)
+ })
+ })
+
+ describe('sellers', () => {
+ it('owner creates a seller with bank details and requisites', async () => {
+ const seller = await owner.billing.createSeller(sellerPayload(orgA))
+ expect(seller.id).toBeGreaterThan(0)
+ expect(seller.archived).toBe(false)
+ expect(seller.requisites[0].label).toBe('VAT ID')
+ sellerId = seller.id
+ })
+
+ it('rejects an empty name and an invalid currency', async () => {
+ const noName = await ownerRaw.post('/module/billing/sellers', { ...sellerPayload(orgA), name: '' })
+ expect(noName.status).toBe(400)
+ const badCurrency = await ownerRaw.post('/module/billing/sellers', { ...sellerPayload(orgA), currencyCode: 'euro' })
+ expect(badCurrency.status).toBe(400)
+ })
+
+ it('ignores foreign keys in the payload instead of failing', async () => {
+ const response = await ownerRaw.patch(`/module/billing/sellers/${sellerId}`, {
+ ...sellerPayload(orgA),
+ organizationId: undefined,
+ id: 999999,
+ createdAt: '2000-01-01',
+ archived: true,
+ legalName: 'Renamed LLC',
+ })
+ expect(response.status).toBe(200)
+ expect(response.data.response.id).toBe(sellerId)
+ expect(response.data.response.archived).toBe(false)
+ expect(response.data.response.legalName).toBe('Renamed LLC')
+ })
+
+ it('a member of the organization cannot see or manage sellers', async () => {
+ const list = await memberRaw.get('/module/billing/sellers', { params: { organizationId: orgA } })
+ expect(list.status).toBe(403)
+ const create = await memberRaw.post('/module/billing/sellers', sellerPayload(orgA))
+ expect(create.status).toBe(403)
+ const update = await memberRaw.patch(`/module/billing/sellers/${sellerId}`, { ...sellerPayload(orgA), organizationId: undefined })
+ expect(update.status).toBe(403)
+ const remove = await memberRaw.delete(`/module/billing/sellers/${sellerId}`)
+ expect(remove.status).toBe(403)
+ })
+
+ it('an owner of another organization cannot reach a seller by id', async () => {
+ const foreign = await member.billing.createSeller(sellerPayload(orgB))
+ foreignSellerId = foreign.id
+ const read = await ownerRaw.patch(`/module/billing/sellers/${foreignSellerId}`, { ...sellerPayload(orgB), organizationId: undefined })
+ expect(read.status).toBe(403)
+ const archive = await ownerRaw.patch(`/module/billing/sellers/${foreignSellerId}/archive`, { archived: true })
+ expect(archive.status).toBe(403)
+ const missing = await ownerRaw.patch('/module/billing/sellers/999999/archive', { archived: true })
+ expect(missing.status).toBe(404)
+ })
+
+ it('archived sellers are hidden from the list unless asked for', async () => {
+ const archived = await owner.billing.archiveSeller({ id: sellerId, archived: true })
+ expect(archived.archived).toBe(true)
+ const hidden = await owner.billing.fetchSellers({ organizationId: orgA })
+ expect(hidden.map((s) => s.id)).not.toContain(sellerId)
+ const shown = await owner.billing.fetchSellers({ organizationId: orgA, includeArchived: true })
+ expect(shown.map((s) => s.id)).toContain(sellerId)
+ const restored = await owner.billing.archiveSeller({ id: sellerId, archived: false })
+ expect(restored.archived).toBe(false)
+ })
+ })
+
+ describe('clients', () => {
+ it('owner creates a client and a person-type client', async () => {
+ const client = await owner.billing.createCounterparty(counterpartyPayload(orgA))
+ expect(client.kind).toBe('organization')
+ counterpartyId = client.id
+ const person = await owner.billing.createCounterparty({ ...counterpartyPayload(orgA), kind: 'person', name: 'John', legalName: '' })
+ expect(person.kind).toBe('person')
+ const removed = await owner.billing.deleteCounterparty(person.id)
+ expect(removed).toBe(true)
+ })
+
+ it('rejects an unknown kind', async () => {
+ const response = await ownerRaw.post('/module/billing/counterparties', { ...counterpartyPayload(orgA), kind: 'alien' })
+ expect(response.status).toBe(400)
+ })
+
+ it('a member cannot list clients', async () => {
+ const response = await memberRaw.get('/module/billing/counterparties', { params: { organizationId: orgA } })
+ expect(response.status).toBe(403)
+ })
+ })
+
+ describe('invoice drafts', () => {
+ it('creates a draft with snapshots, project name and computed totals', async () => {
+ const invoice = await owner.invoices.create(invoicePayload('E2E-0001'))
+ invoiceId = invoice.id
+ expect(invoice.status).toBe('draft')
+ expect(invoice.goalName).toBe('billing-e2e-goal')
+ expect(invoice.seller.legalName).toBe('Renamed LLC')
+ expect(invoice.counterparty.contactPerson).toBe('Anna')
+ expect(invoice.lines).toHaveLength(2)
+ expect(invoice.lines[1].quantity).toBe(10.5)
+ expect(invoice.totalsFrozen).toBe(false)
+ expect(invoice.totals).toEqual({ subtotal: 1840, discount: 184, taxable: 1656, tax: 314.64, total: 1970.64 })
+ expect(invoice.issuedAt).toBeNull()
+ expect(invoice.replacesInvoiceId).toBeNull()
+ })
+
+ it('refuses a duplicate number inside the organization and allows it in another', async () => {
+ const duplicate = await ownerRaw.post('/module/invoices', invoicePayload('E2E-0001'))
+ expect(duplicate.status).toBe(409)
+
+ const foreignClient = await member.billing.createCounterparty(counterpartyPayload(orgB))
+ const sameNumberElsewhere = await member.invoices.create({
+ ...invoicePayload('E2E-0001'),
+ organizationId: orgB,
+ goalId: null,
+ sellerId: foreignSellerId,
+ counterpartyId: foreignClient.id,
+ })
+ expect(sameNumberElsewhere.number).toBe('E2E-0001')
+ expect(sameNumberElsewhere.goalId).toBeNull()
+ expect(sameNumberElsewhere.goalName).toBe('')
+ })
+
+ it('refuses a seller, a client or a project from another organization', async () => {
+ const seller = await ownerRaw.post('/module/invoices', { ...invoicePayload('E2E-0002'), sellerId: foreignSellerId })
+ expect(seller.status).toBe(422)
+ expect(seller.data).toBe('seller_not_found')
+ const client = await ownerRaw.post('/module/invoices', { ...invoicePayload('E2E-0002'), counterpartyId: 999999 })
+ expect(client.status).toBe(422)
+ const goal = await ownerRaw.post('/module/invoices', { ...invoicePayload('E2E-0002'), goalId: 999999 })
+ expect(goal.status).toBe(422)
+ })
+
+ it('validates dates, enums and lines', async () => {
+ const badDate = await ownerRaw.post('/module/invoices', { ...invoicePayload('E2E-0002'), issueDate: '06.09.2026' })
+ expect(badDate.status).toBe(400)
+ const badUnit = await ownerRaw.post('/module/invoices', {
+ ...invoicePayload('E2E-0002'),
+ lines: [{ taskId: null, description: 'x', unit: 'kg', quantity: 1, unitPrice: 1 }],
+ })
+ expect(badUnit.status).toBe(400)
+ const noLines = await ownerRaw.post('/module/invoices', { ...invoicePayload('E2E-0002'), lines: [] })
+ expect(noLines.status).toBe(400)
+ const negative = await ownerRaw.post('/module/invoices', { ...invoicePayload('E2E-0002'), discountValue: -5 })
+ expect(negative.status).toBe(400)
+ })
+
+ it('replaces lines and recomputes totals on update', async () => {
+ const { organizationId: _org, ...data } = invoicePayload('E2E-0001')
+ const updated = await owner.invoices.update({
+ id: invoiceId,
+ data: { ...data, discountValue: 0, taxExempt: true, lines: [{ taskId: null, description: 'Only', unit: 'pcs', quantity: 2, unitPrice: 5 }] },
+ })
+ expect(updated.lines).toHaveLength(1)
+ expect(updated.totals.total).toBe(10)
+ await owner.invoices.update({ id: invoiceId, data })
+ })
+
+ it('lists invoices of the organization and hides those of archived clients', async () => {
+ const visible = await owner.invoices.fetch({ organizationId: orgA })
+ expect(visible.map((i) => i.id)).toContain(invoiceId)
+
+ await owner.billing.archiveCounterparty({ id: counterpartyId, archived: true })
+ const hidden = await owner.invoices.fetch({ organizationId: orgA })
+ expect(hidden.map((i) => i.id)).not.toContain(invoiceId)
+ const shown = await owner.invoices.fetch({ organizationId: orgA, includeArchived: true })
+ expect(shown.map((i) => i.id)).toContain(invoiceId)
+ await owner.billing.archiveCounterparty({ id: counterpartyId, archived: false })
+ })
+
+ it('a member and a foreign owner cannot read the invoice', async () => {
+ const asMember = await memberRaw.get(`/module/invoices/${invoiceId}`)
+ expect(asMember.status).toBe(403)
+ const list = await memberRaw.get('/module/invoices', { params: { organizationId: orgA } })
+ expect(list.status).toBe(403)
+ const pdf = await memberRaw.get(`/module/invoices/${invoiceId}/pdf`)
+ expect(pdf.status).toBe(403)
+ })
+
+ it('a seller or a client with invoices cannot be deleted', async () => {
+ const seller = await ownerRaw.delete(`/module/billing/sellers/${sellerId}`)
+ expect(seller.status).toBe(409)
+ const client = await ownerRaw.delete(`/module/billing/counterparties/${counterpartyId}`)
+ expect(client.status).toBe(409)
+ })
+ })
+
+ describe('invoice lifecycle', () => {
+ it('cannot be paid or voided while it is a draft', async () => {
+ const paid = await ownerRaw.patch(`/module/invoices/${invoiceId}/status`, { status: 'paid' })
+ expect(paid.status).toBe(409)
+ expect(paid.data.error).toBe('invalid_transition')
+ const voided = await ownerRaw.patch(`/module/invoices/${invoiceId}/status`, { status: 'void' })
+ expect(voided.status).toBe(409)
+ })
+
+ it('cannot be corrected while it is a draft', async () => {
+ const response = await ownerRaw.post(`/module/invoices/${invoiceId}/reissue`, {})
+ expect(response.status).toBe(409)
+ })
+
+ it('reports every missing requisite before issuing', async () => {
+ const response = await ownerRaw.patch(`/module/invoices/${invoiceId}/status`, { status: 'issued' })
+ expect(response.status).toBe(422)
+ expect(response.data.error).toBe('missing_requisites')
+ expect(response.data.missing).toEqual(expect.arrayContaining(['seller.address', 'seller.bank', 'counterparty.address']))
+ })
+
+ it('issues once the requisites are complete and freezes the totals', async () => {
+ const { organizationId: _s, ...seller } = sellerPayload(orgA)
+ await owner.billing.updateSeller({ id: sellerId, data: { ...seller, address: 'Seller street 1', bank: { ...seller.bank, iban: 'DE00' } } })
+ const { organizationId: _c, ...client } = counterpartyPayload(orgA)
+ await owner.billing.updateCounterparty({ id: counterpartyId, data: { ...client, address: 'Client street 2' } })
+ const { organizationId: _i, ...data } = invoicePayload('E2E-0001')
+ await owner.invoices.update({ id: invoiceId, data })
+
+ const issued = await owner.invoices.setStatus({ id: invoiceId, status: 'issued' })
+ expect(issued.status).toBe('issued')
+ expect(issued.issuedAt).toBeTruthy()
+ expect(issued.totalsFrozen).toBe(true)
+ expect(issued.totals.total).toBe(1970.64)
+ expect(issued.seller.address).toBe('Seller street 1')
+ expect(issued.templateVersion).toBe(1)
+ })
+
+ it('an issued invoice keeps its snapshot when the seller changes again', async () => {
+ const { organizationId: _s, ...seller } = sellerPayload(orgA)
+ await owner.billing.updateSeller({ id: sellerId, data: { ...seller, address: 'Moved elsewhere', bank: { ...seller.bank, iban: 'DE99' } } })
+ const invoice = await owner.invoices.fetchById(invoiceId)
+ expect(invoice.seller.address).toBe('Seller street 1')
+ expect(invoice.seller.bank.iban).toBe('DE00')
+ })
+
+ it('cannot be edited, deleted or moved back to draft after issue', async () => {
+ const { organizationId: _i, ...data } = invoicePayload('E2E-0001')
+ const edit = await ownerRaw.patch(`/module/invoices/${invoiceId}`, data)
+ expect(edit.status).toBe(409)
+ expect(edit.data).toBe('not_draft')
+ const remove = await ownerRaw.delete(`/module/invoices/${invoiceId}`)
+ expect(remove.status).toBe(409)
+ const back = await ownerRaw.patch(`/module/invoices/${invoiceId}/status`, { status: 'draft' })
+ expect(back.status).toBe(409)
+ })
+
+ it('marks paid, refuses to void a paid invoice, and unmarks', async () => {
+ const paid = await owner.invoices.setStatus({ id: invoiceId, status: 'paid' })
+ expect(paid.paidAt).toBeTruthy()
+ const voided = await ownerRaw.patch(`/module/invoices/${invoiceId}/status`, { status: 'void' })
+ expect(voided.status).toBe(409)
+ const draft = await ownerRaw.patch(`/module/invoices/${invoiceId}/status`, { status: 'draft' })
+ expect(draft.status).toBe(409)
+ const unpaid = await owner.invoices.setStatus({ id: invoiceId, status: 'issued' })
+ expect(unpaid.paidAt).toBeNull()
+ expect(unpaid.issuedAt).toBeTruthy()
+ })
+
+ it('renders the PDF in both languages', async () => {
+ for (const lang of ['en', 'ru'] as const) {
+ const blob = await owner.invoices.fetchPdf({ id: invoiceId, lang })
+ const bytes = Buffer.from(await blob.arrayBuffer())
+ expect(bytes.subarray(0, 4).toString()).toBe('%PDF')
+ expect(bytes.length).toBeGreaterThan(1000)
+ }
+ const bad = await ownerRaw.get(`/module/invoices/${invoiceId}/pdf`, { params: { lang: 'fr' } })
+ expect(bad.status).toBe(400)
+ })
+
+ it('corrects an issued invoice: voids it and opens a replacement draft with the next number', async () => {
+ const copy = await owner.invoices.reissue(invoiceId)
+ expect(copy.status).toBe('draft')
+ expect(copy.number).toBe('E2E-0002')
+ expect(copy.replacesInvoiceId).toBe(invoiceId)
+ expect(copy.lines).toHaveLength(2)
+ expect(copy.totalsFrozen).toBe(false)
+ expect(copy.seller.address).toBe('Moved elsewhere')
+
+ const original = await owner.invoices.fetchById(invoiceId)
+ expect(original.status).toBe('void')
+ expect(original.voidedAt).toBeTruthy()
+ expect(original.totalsFrozen).toBe(true)
+
+ const revive = await ownerRaw.patch(`/module/invoices/${invoiceId}/status`, { status: 'issued' })
+ expect(revive.status).toBe(409)
+ const removeVoid = await ownerRaw.delete(`/module/invoices/${invoiceId}`)
+ expect(removeVoid.status).toBe(409)
+
+ const again = await owner.invoices.reissue(invoiceId)
+ expect(again.number).toBe('E2E-0003')
+ expect(await owner.invoices.delete(again.id)).toBe(true)
+ expect(await owner.invoices.delete(copy.id)).toBe(true)
+ })
+
+ it('the voided invoice renders with the void watermark and is still not deletable', async () => {
+ const blob = await owner.invoices.fetchPdf({ id: invoiceId, lang: 'en' })
+ expect(Buffer.from(await blob.arrayBuffer()).subarray(0, 4).toString()).toBe('%PDF')
+ const remove = await ownerRaw.delete(`/module/invoices/${invoiceId}`)
+ expect(remove.status).toBe(409)
+ })
+ })
+
+ describe('API tokens', () => {
+ it('a token without billing_can_manage is refused, a token with it is accepted', async () => {
+ const narrow = await owner.apiTokens.create({ name: 'e2e-narrow', allowedPermissions: ['goal_can_watch_content'] })
+ const wide = await owner.apiTokens.create({ name: 'e2e-billing', allowedPermissions: ['billing_can_manage'] })
+ const withToken = (token: string) =>
+ axios.create({ baseURL: API_URL, headers: { Authorization: `Bearer ${token}` }, validateStatus: () => true })
+
+ const refused = await withToken(narrow.token).get('/module/invoices', { params: { organizationId: orgA } })
+ expect(refused.status).toBe(403)
+ const accepted = await withToken(wide.token).get('/module/invoices', { params: { organizationId: orgA } })
+ expect(accepted.status).toBe(200)
+ const unrestricted = await owner.apiTokens.create({ name: 'e2e-unrestricted' })
+ const passes = await withToken(unrestricted.token).get('/module/billing/sellers', { params: { organizationId: orgA } })
+ expect(passes.status).toBe(200)
+
+ for (const item of [narrow, wide, unrestricted]) await owner.apiTokens.delete(item.item.id)
+ })
+ })
+
+ describe('organization deletion', () => {
+ it('removes the organization together with its billing records', async () => {
+ const deleted = await owner.organizations.delete(orgA)
+ expect(deleted).toBeTruthy()
+ const seller = await ownerRaw.patch(`/module/billing/sellers/${sellerId}/archive`, { archived: true })
+ expect(seller.status).toBe(404)
+ const invoice = await ownerRaw.get(`/module/invoices/${invoiceId}`)
+ expect(invoice.status).toBe(404)
+ orgA = 0
+ })
+ })
+})
diff --git a/web/src/components/features/invoices/InvoiceActions.vue b/web/src/components/features/invoices/InvoiceActions.vue
index 2fa092f..910b0ab 100644
--- a/web/src/components/features/invoices/InvoiceActions.vue
+++ b/web/src/components/features/invoices/InvoiceActions.vue
@@ -3,14 +3,16 @@
v-if="invoice.status === 'draft'"
icon="i-lucide-pencil"
:label="compact ? undefined : t('common.edit')"
+ :aria-label="t('common.edit')"
color="neutral"
- variant="outline"
+ variant="soft"
@click="emit('edit')"
/>
<UButton
v-if="invoice.status === 'draft'"
icon="i-lucide-send"
:label="compact ? undefined : t('invoices.actions.issue')"
+ :aria-label="t('invoices.actions.issue')"
variant="soft"
:loading="busy"
@click="emit('transition', 'issued')"
@@ -19,6 +21,7 @@
v-if="invoice.status === 'issued'"
icon="i-lucide-badge-check"
:label="compact ? undefined : t('invoices.actions.markPaid')"
+ :aria-label="t('invoices.actions.markPaid')"
variant="soft"
:loading="busy"
@click="emit('transition', 'paid')"
@@ -27,8 +30,9 @@
v-if="invoice.status === 'issued'"
icon="i-lucide-file-pen-line"
:label="compact ? undefined : t('invoices.actions.reissue')"
+ :aria-label="t('invoices.actions.reissue')"
color="neutral"
- variant="outline"
+ variant="soft"
:loading="busy"
@click="emit('reissue')"
/>
@@ -36,8 +40,9 @@
v-if="invoice.status === 'issued'"
icon="i-lucide-ban"
:label="compact ? undefined : t('invoices.actions.void')"
+ :aria-label="t('invoices.actions.void')"
color="error"
- variant="ghost"
+ variant="soft"
:loading="busy"
@click="emit('transition', 'void')"
/>
@@ -45,8 +50,9 @@
v-if="invoice.status === 'paid'"
icon="i-lucide-undo-2"
:label="compact ? undefined : t('invoices.actions.unmarkPaid')"
+ :aria-label="t('invoices.actions.unmarkPaid')"
color="neutral"
- variant="outline"
+ variant="soft"
:loading="busy"
@click="emit('transition', 'issued')"
/>
@@ -54,8 +60,9 @@
v-if="invoice.status === 'void'"
icon="i-lucide-file-pen-line"
:label="compact ? undefined : t('invoices.actions.reissue')"
+ :aria-label="t('invoices.actions.reissue')"
color="neutral"
- variant="outline"
+ variant="soft"
:loading="busy"
@click="emit('reissue')"
/>
diff --git a/web/src/components/features/invoices/InvoicePdfViewer.vue b/web/src/components/features/invoices/InvoicePdfViewer.vue
index 1109903..9217520 100644
--- a/web/src/components/features/invoices/InvoicePdfViewer.vue
+++ b/web/src/components/features/invoices/InvoicePdfViewer.vue
@@ -1,5 +1,5 @@
<template>
- <div class="flex h-full min-h-[60vh] flex-col">
+ <div class="flex min-h-[60vh] flex-col">
<div
v-if="loading"
class="flex flex-1 items-center justify-center text-muted"
@@ -19,7 +19,7 @@
v-else
:src="url"
:title="title"
- class="h-full min-h-[70vh] w-full flex-1 rounded-10 bg-white"
+ class="min-h-0 w-full flex-1 rounded-lg bg-white"
/>
</div>
</template>
diff --git a/web/src/components/features/invoices/InvoicesPageShell.vue b/web/src/components/features/invoices/InvoicesPageShell.vue
index 450e966..ab01546 100644
--- a/web/src/components/features/invoices/InvoicesPageShell.vue
+++ b/web/src/components/features/invoices/InvoicesPageShell.vue
@@ -1,5 +1,8 @@
<template>
- <UDashboardPanel :id="id">
+ <UDashboardPanel
+ :id="id"
+ :ui="fillBody ? { body: 'flex flex-col' } : undefined"
+ >
<template #header>
<UDashboardNavbar :title="title">
<template #leading>
@@ -44,8 +47,9 @@ withDefaults(
id: string
title: string
showTabs?: boolean
+ fillBody?: boolean
}>(),
- { showTabs: true },
+ { showTabs: true, fillBody: false },
)
const includeArchived = defineModel<boolean | undefined>('includeArchived', { default: undefined })
diff --git a/web/src/components/features/invoices/parts/CounterpartyForm.vue b/web/src/components/features/invoices/parts/CounterpartyForm.vue
index e9971c7..a07e7be 100644
--- a/web/src/components/features/invoices/parts/CounterpartyForm.vue
+++ b/web/src/components/features/invoices/parts/CounterpartyForm.vue
@@ -5,9 +5,9 @@
v-model="model.kind"
:items="kindItems"
:content="false"
- size="lg"
- class="w-full lg:w-80"
- :ui="{ list: 'rounded-14', trigger: 'rounded-10', indicator: 'rounded-10' }"
+ size="xl"
+ class="w-full"
+ :ui="{ list: 'rounded-xl p-1', trigger: 'rounded-lg', indicator: 'rounded-lg' }"
/>
</UFormField>
diff --git a/web/src/components/features/invoices/parts/CurrencySelect.vue b/web/src/components/features/invoices/parts/CurrencySelect.vue
new file mode 100644
index 0000000..179519a
--- /dev/null
+++ b/web/src/components/features/invoices/parts/CurrencySelect.vue
@@ -0,0 +1,23 @@
+<template>
+ <USelectMenu
+ v-model="model"
+ :items="options"
+ value-key="value"
+ :search-input="false"
+ size="xl"
+ :variant="inputVariant"
+ :ui="inputUi"
+ class="w-full"
+ />
+</template>
+
+<script setup lang="ts">
+import { storeToRefs } from 'pinia'
+import { useCurrenciesStore } from '@/stores/currencies.store'
+import { useInvoiceFieldStyle } from '@/composables/useInvoiceFieldStyle'
+
+const model = defineModel<string>({ required: true })
+
+const { options } = storeToRefs(useCurrenciesStore())
+const { inputVariant, inputUi } = useInvoiceFieldStyle()
+</script>
diff --git a/web/src/components/features/invoices/parts/InvoiceFormHeader.vue b/web/src/components/features/invoices/parts/InvoiceFormHeader.vue
index 25da83d..a3aa607 100644
--- a/web/src/components/features/invoices/parts/InvoiceFormHeader.vue
+++ b/web/src/components/features/invoices/parts/InvoiceFormHeader.vue
@@ -31,15 +31,7 @@
:label="t('invoices.fields.currency')"
class="lg:w-40"
>
- <USelectMenu
- v-model="model.currencyCode"
- :items="currencyItems"
- value-key="value"
- size="xl"
- :variant="inputVariant"
- :ui="inputUi"
- class="w-full"
- />
+ <CurrencySelect v-model="model.currencyCode" />
</UFormField>
</div>
@@ -122,8 +114,7 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { useInvoiceFieldStyle } from '@/composables/useInvoiceFieldStyle'
-import { storeToRefs } from 'pinia'
-import { useCurrenciesStore } from '@/stores/currencies.store'
+import CurrencySelect from './CurrencySelect.vue'
import type { InvoiceFormValue, InvoiceSelectOption } from '@/types/invoices.types'
const model = defineModel<InvoiceFormValue>({ required: true })
@@ -144,5 +135,4 @@ const emit = defineEmits<{
const { t } = useI18n()
const { inputVariant, inputUi } = useInvoiceFieldStyle()
-const { options: currencyItems } = storeToRefs(useCurrenciesStore())
</script>
diff --git a/web/src/components/features/invoices/parts/InvoiceLinesEditor.vue b/web/src/components/features/invoices/parts/InvoiceLinesEditor.vue
index 42bb3a6..6c9a411 100644
--- a/web/src/components/features/invoices/parts/InvoiceLinesEditor.vue
+++ b/web/src/components/features/invoices/parts/InvoiceLinesEditor.vue
@@ -1,5 +1,8 @@
<template>
- <div :class="sectionClass">
+ <div
+ :class="sectionClass"
+ class="gap-4 md:gap-3"
+ >
<span class="text-sm font-medium text-default">{{ t('invoices.lines.title') }} <span class="text-error">*</span></span>
<p
@@ -11,7 +14,7 @@
<div
v-else
- class="hidden lg:grid lg:grid-cols-[1fr_9rem_5.5rem_7.5rem_6.5rem_2.5rem] gap-2 px-1 text-xs text-muted"
+ class="hidden md:grid md:grid-cols-[1fr_9rem_5.5rem_7.5rem_6.5rem_2.5rem] gap-2 px-1 text-xs text-muted"
>
<span>{{ t('invoices.lines.description') }}</span>
<span>{{ t('invoices.lines.unit') }}</span>
@@ -24,7 +27,7 @@
<div
v-for="line in lines"
:key="line.key"
- class="grid grid-cols-[1fr_auto] gap-2 rounded-10 bg-elevated/40 p-2 lg:grid-cols-[1fr_9rem_5.5rem_7.5rem_6.5rem_2.5rem] lg:items-center lg:bg-transparent lg:p-0"
+ class="grid grid-cols-[1fr_auto] gap-x-2 gap-y-3 rounded-[20px] bg-elevated p-3 shadow-sm dark:max-sm:bg-default/70 dark:shadow-none md:grid-cols-[1fr_9rem_5.5rem_7.5rem_6.5rem_2.5rem] md:items-center md:gap-2 md:bg-transparent md:p-0 md:shadow-none"
>
<UInput
v-model="line.description"
@@ -40,10 +43,10 @@
color="neutral"
variant="ghost"
size="sm"
- class="lg:order-last"
+ class="self-center md:order-last"
@click="emit('remove', line.key)"
/>
- <div class="col-span-2 grid grid-cols-[1.4fr_1fr_1fr] gap-2 lg:contents">
+ <div class="col-span-2 grid grid-cols-[1.2fr_0.8fr_1.3fr] gap-2 md:contents">
<UFormField
:label="t('invoices.lines.unit')"
:ui="fieldUi"
@@ -90,7 +93,13 @@
/>
</UFormField>
</div>
- <span class="col-span-2 text-right text-sm tabular-nums text-default lg:col-span-1">
+ <div class="col-span-2 flex items-center justify-between border-t border-default pt-2 text-sm md:hidden">
+ <span class="text-muted">{{ t('invoices.lines.amount') }}</span>
+ <span class="font-semibold tabular-nums text-default">
+ {{ formatMoney({ amount: lineAmount(line.quantity, line.unitPrice), currencyCode, locale }) }}
+ </span>
+ </div>
+ <span class="hidden text-right text-sm tabular-nums text-default md:block">
{{ formatMoney({ amount: lineAmount(line.quantity, line.unitPrice), currencyCode, locale }) }}
</span>
</div>
@@ -129,7 +138,7 @@ const emit = defineEmits<{
const { t, locale } = useI18n()
const { inputVariant, inputUi, sectionClass } = useInvoiceFieldStyle()
-const fieldUi = { label: 'lg:hidden', container: 'lg:mt-0' }
+const fieldUi = { label: 'md:hidden', container: 'md:mt-0' }
const unitItems = computed(() => INVOICE_UNITS.map((unit) => ({ label: t(`invoices.units.${unit}`), value: unit })))
diff --git a/web/src/components/features/invoices/parts/InvoiceTaskPicker.vue b/web/src/components/features/invoices/parts/InvoiceTaskPicker.vue
index 5e3d546..4e3022f 100644
--- a/web/src/components/features/invoices/parts/InvoiceTaskPicker.vue
+++ b/web/src/components/features/invoices/parts/InvoiceTaskPicker.vue
@@ -32,7 +32,7 @@
<div
v-else
- class="flex flex-col divide-y divide-default rounded-10 bg-elevated/50 max-h-64 overflow-y-auto"
+ class="flex flex-col divide-y divide-default rounded-lg bg-elevated/50 max-h-64 overflow-y-auto"
>
<label
v-for="task in tasks"
diff --git a/web/src/components/features/invoices/parts/InvoiceTotalsEditor.vue b/web/src/components/features/invoices/parts/InvoiceTotalsEditor.vue
index cbf64c7..7277600 100644
--- a/web/src/components/features/invoices/parts/InvoiceTotalsEditor.vue
+++ b/web/src/components/features/invoices/parts/InvoiceTotalsEditor.vue
@@ -81,7 +81,7 @@
</UFormField>
</div>
- <dl class="grid grid-cols-[1fr_auto] gap-x-6 gap-y-1 rounded-14 bg-elevated px-4 py-3 text-sm lg:w-72">
+ <dl class="grid grid-cols-[1fr_auto] gap-x-6 gap-y-1 rounded-lg bg-elevated px-4 py-3 text-sm lg:w-72">
<dt class="text-muted">
{{ t('invoices.totals.subtotal') }}
</dt>
diff --git a/web/src/components/features/invoices/parts/SellerForm.vue b/web/src/components/features/invoices/parts/SellerForm.vue
index a48dff2..cc5ebea 100644
--- a/web/src/components/features/invoices/parts/SellerForm.vue
+++ b/web/src/components/features/invoices/parts/SellerForm.vue
@@ -20,15 +20,7 @@
:label="t('invoices.fields.currency')"
class="lg:w-40"
>
- <USelectMenu
- v-model="model.currencyCode"
- :items="currencyItems"
- value-key="value"
- size="xl"
- :variant="inputVariant"
- :ui="inputUi"
- class="w-full"
- />
+ <CurrencySelect v-model="model.currencyCode" />
</UFormField>
</div>
@@ -64,8 +56,7 @@ import { useI18n } from 'vue-i18n'
import { useInvoiceFieldStyle } from '@/composables/useInvoiceFieldStyle'
import PartyFields from './PartyFields.vue'
import BankDetailsFields from './BankDetailsFields.vue'
-import { storeToRefs } from 'pinia'
-import { useCurrenciesStore } from '@/stores/currencies.store'
+import CurrencySelect from './CurrencySelect.vue'
import type { SellerFormValue } from '@/types/invoices.types'
const model = defineModel<SellerFormValue>({ required: true })
@@ -73,6 +64,5 @@ const model = defineModel<SellerFormValue>({ required: true })
const { t } = useI18n()
const { inputVariant, inputUi } = useInvoiceFieldStyle()
-const { options: currencyItems } = storeToRefs(useCurrenciesStore())
</script>
diff --git a/web/src/composables/useInvoiceFieldStyle.ts b/web/src/composables/useInvoiceFieldStyle.ts
index fec5f6c..d3d5b97 100644
--- a/web/src/composables/useInvoiceFieldStyle.ts
+++ b/web/src/composables/useInvoiceFieldStyle.ts
@@ -2,12 +2,12 @@
// background, no ring) in both themes, 14px radius.
export function useInvoiceFieldStyle() {
const inputVariant = 'soft' as const
- const inputUi = { base: 'rounded-14' }
+ const inputUi = { base: 'rounded-xl dark:bg-accented/40 dark:hover:bg-accented/60 dark:focus:bg-accented/60' }
const dateButtonVariant = 'soft' as const
- const dateButtonUi = { base: 'rounded-14 justify-start', leadingIcon: 'size-4.5' }
+ const dateButtonUi = { base: 'rounded-xl justify-start dark:bg-accented/40 dark:hover:bg-accented/60', leadingIcon: 'size-4.5' }
- const sectionClass = 'flex flex-col gap-3 rounded-14 p-3 shadow-sm dark:bg-tv-ui-bg-elevated'
+ const sectionClass = 'flex flex-col gap-3 rounded-2xl p-3 shadow-sm dark:bg-tv-ui-bg-elevated'
return { inputVariant, inputUi, dateButtonVariant, dateButtonUi, sectionClass }
}
diff --git a/web/src/pages/user/invoice-preview.vue b/web/src/pages/user/invoice-preview.vue
index 2e6703d..b4b5546 100644
--- a/web/src/pages/user/invoice-preview.vue
+++ b/web/src/pages/user/invoice-preview.vue
@@ -3,11 +3,13 @@
id="invoice-preview"
:title="invoice ? invoice.number : t('invoices.page.title')"
:show-tabs="false"
+ fill-body
>
<template #actions>
<UButton
icon="i-lucide-arrow-left"
:label="isMobile ? undefined : t('invoices.preview.back')"
+ :aria-label="t('invoices.preview.back')"
color="neutral"
variant="ghost"
:to="{ name: 'invoices' }"
@@ -25,6 +27,8 @@
v-if="invoice"
icon="i-lucide-download"
:label="isMobile ? undefined : t('invoices.preview.download')"
+ :aria-label="t('invoices.preview.download')"
+ variant="soft"
:disabled="!pdfBlob"
@click="download"
/>
@@ -48,13 +52,14 @@
</div>
<div
v-else
- class="flex flex-col gap-3 p-2 lg:p-6"
+ class="flex min-h-0 flex-1 flex-col gap-3"
>
<InvoiceStatusBar :invoice="invoice" />
<InvoicePdfViewer
:invoice-id="invoice.id"
:title="invoice.number"
:version="invoice.updatedAt"
+ class="min-h-0 flex-1"
@loaded="pdfBlob = $event"
/>
</div>
diff --git a/web/src/pages/user/invoices-counterparties.vue b/web/src/pages/user/invoices-counterparties.vue
index 486e1d0..2573d35 100644
--- a/web/src/pages/user/invoices-counterparties.vue
+++ b/web/src/pages/user/invoices-counterparties.vue
@@ -11,6 +11,7 @@
v-if="isAdmin"
icon="i-lucide-plus"
:label="t('invoices.counterparty.create')"
+ variant="soft"
@click="openCreate"
/>
</template>
diff --git a/web/src/pages/user/invoices-sellers.vue b/web/src/pages/user/invoices-sellers.vue
index 4d31cae..942653f 100644
--- a/web/src/pages/user/invoices-sellers.vue
+++ b/web/src/pages/user/invoices-sellers.vue
@@ -11,6 +11,7 @@
v-if="isAdmin"
icon="i-lucide-plus"
:label="t('invoices.seller.create')"
+ variant="soft"
@click="openCreate"
/>
</template>
diff --git a/web/src/pages/user/invoices.vue b/web/src/pages/user/invoices.vue
index f589223..41d8a1f 100644
--- a/web/src/pages/user/invoices.vue
+++ b/web/src/pages/user/invoices.vue
@@ -11,6 +11,7 @@
v-if="isAdmin"
icon="i-lucide-plus"
:label="t('invoices.create')"
+ variant="soft"
@click="formOpen = true"
/>
</template>
diff --git a/web/src/types/invoices.types.ts b/web/src/types/invoices.types.ts
index 377db1f..dc29c25 100644
--- a/web/src/types/invoices.types.ts
+++ b/web/src/types/invoices.types.ts
@@ -159,4 +159,4 @@ export const PAYMENT_TERMS_DAYS: Record<InvoicePaymentTerms, number | null> = {
custom: null,
}
-export const REQUISITE_PRESETS = ['ИНН', 'КПП', 'ОГРН', 'VAT ID', 'EIN', 'Reg. No.']
+export const REQUISITE_PRESETS = ['VAT ID', 'EIN', 'Reg. No.', 'ИНН', 'КПП', 'ОГРН']