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 mobile issues

Nikolai Gimandaee7a6f694e
diff --git a/api/src/tv-modules/invoices/InvoicePdfRenderer.ts b/api/src/tv-modules/invoices/InvoicePdfRenderer.ts
index af5fb15..a8a7633 100644
--- a/api/src/tv-modules/invoices/InvoicePdfRenderer.ts
+++ b/api/src/tv-modules/invoices/InvoicePdfRenderer.ts
@@ -89,7 +89,7 @@ export class InvoicePdfRenderer {
return this.pdfmake.createPdf(this.buildDocument(invoice, lang)).getBuffer()
}
- private buildDocument(invoice: InvoiceForClient, lang: InvoicePdfLang) {
+ buildDocument(invoice: InvoiceForClient, lang: InvoicePdfLang) {
const t = LABELS[lang]
const money = (amount: number) => this.formatMoney(amount, invoice.currencyCode, lang)
const date = (value: string | null) => this.formatDate(value, lang)
diff --git a/api/src/tv-modules/invoices/__tests__/InvoicePdfRenderer.spec.ts b/api/src/tv-modules/invoices/__tests__/InvoicePdfRenderer.spec.ts
new file mode 100644
index 0000000..e2f67c9
--- /dev/null
+++ b/api/src/tv-modules/invoices/__tests__/InvoicePdfRenderer.spec.ts
@@ -0,0 +1,192 @@
+import { describe, expect, it } from 'vitest'
+import { InvoicePdfRenderer } from '../InvoicePdfRenderer'
+import type { InvoiceForClient } from '../types'
+
+function collectTexts(node: unknown, out: string[] = []): string[] {
+ if (typeof node === 'string') out.push(node)
+ else if (Array.isArray(node)) node.forEach(child => collectTexts(child, out))
+ else if (node && typeof node === 'object') Object.values(node).forEach(value => collectTexts(value, out))
+ return out
+}
+
+function expectText(texts: string[], value: string) {
+ expect(texts.some(text => text.includes(value)), `expected "${value}" in the document`).toBe(true)
+}
+
+function expectNoText(texts: string[], value: string) {
+ expect(texts.some(text => text.includes(value)), `did not expect "${value}" in the document`).toBe(false)
+}
+
+function fullInvoice(): InvoiceForClient {
+ return {
+ id: 7,
+ organizationId: 1,
+ goalId: 2,
+ goalName: 'Website',
+ sellerId: 3,
+ counterpartyId: 4,
+ number: 'INV-2026-007',
+ status: 'issued',
+ reference: 'PO-42',
+ currencyCode: 'EUR',
+ issueDate: '2026-09-01',
+ paymentTerms: 'net14',
+ dueDate: '2026-09-15',
+ periodFrom: '2026-08-01',
+ periodTo: '2026-08-31',
+ discountType: 'percent',
+ discountValue: 10,
+ taxRate: 19,
+ taxExempt: false,
+ taxNote: '',
+ notes: 'Thank you for your business',
+ terms: 'Payment within 14 days',
+ createdBy: 1,
+ issuedAt: new Date('2026-09-01T10:00:00Z'),
+ paidAt: null,
+ voidedAt: null,
+ replacesInvoiceId: null,
+ templateVersion: 1,
+ createdAt: new Date('2026-09-01T10:00:00Z'),
+ updatedAt: new Date('2026-09-01T10:00:00Z'),
+ seller: {
+ name: 'Acme Studio',
+ legalName: 'Acme Studio LLC',
+ address: 'Baker st 221b, London',
+ email: '[email protected]',
+ phone: '+44 20 1234',
+ logoUrl: 'https://acme.test/logo.png',
+ bank: {
+ bankName: 'Barclays',
+ accountNumber: '40817810',
+ iban: 'GB29NWBK',
+ swift: 'BARCGB22',
+ correspondentAccount: '30101810',
+ },
+ requisites: [
+ { key: 'vat', label: 'VAT ID', value: 'GB123456' },
+ { key: 'reg', label: 'Reg. No', value: '0987' },
+ ],
+ },
+ counterparty: {
+ kind: 'organization',
+ name: 'Globex',
+ legalName: 'Globex GmbH',
+ address: 'Hauptstr. 5, Berlin',
+ email: '[email protected]',
+ phone: '+49 30 555',
+ contactPerson: 'Anna Schmidt',
+ requisites: [{ key: 'vat', label: 'USt-IdNr.', value: 'DE999' }],
+ },
+ lines: [
+ { id: 1, taskId: null, description: 'Design work', unit: 'hours', quantity: 10.5, unitPrice: 80 },
+ { id: 2, taskId: 5, description: 'Hosting', unit: 'pcs', quantity: 2, unitPrice: 15 },
+ ],
+ totals: { subtotal: 870, discount: 87, taxable: 783, tax: 148.77, total: 931.77 },
+ totalsFrozen: true,
+ }
+}
+
+describe('InvoicePdfRenderer', () => {
+ const renderer = new InvoicePdfRenderer()
+
+ it('prints every seller field', () => {
+ const texts = collectTexts(renderer.buildDocument(fullInvoice(), 'en'))
+ expectText(texts, 'Acme Studio LLC')
+ expectText(texts, 'Baker st 221b, London')
+ expectText(texts, 'VAT ID: GB123456')
+ expectText(texts, 'Reg. No: 0987')
+ expectText(texts, '[email protected]')
+ expectText(texts, '+44 20 1234')
+ expectText(texts, 'PAYMENT DETAILS')
+ expectText(texts, 'Barclays')
+ expectText(texts, '40817810')
+ expectText(texts, 'GB29NWBK')
+ expectText(texts, 'BARCGB22')
+ expectText(texts, '30101810')
+ })
+
+ it('prints every counterparty field', () => {
+ const texts = collectTexts(renderer.buildDocument(fullInvoice(), 'en'))
+ expectText(texts, 'BILL TO')
+ expectText(texts, 'Globex GmbH')
+ expectText(texts, 'Anna Schmidt')
+ expectText(texts, 'Hauptstr. 5, Berlin')
+ expectText(texts, 'USt-IdNr.: DE999')
+ expectText(texts, '[email protected]')
+ expectText(texts, '+49 30 555')
+ })
+
+ it('prints the invoice meta, lines, totals, terms and notes', () => {
+ const texts = collectTexts(renderer.buildDocument(fullInvoice(), 'en'))
+ expectText(texts, 'INV-2026-007')
+ expectText(texts, 'PO-42')
+ expectText(texts, '01.09.2026')
+ expectText(texts, '15.09.2026')
+ expectText(texts, '01.08.2026 – 31.08.2026')
+ expectText(texts, 'Design work')
+ expectText(texts, '10.5')
+ expectText(texts, 'Hosting')
+ expectText(texts, '870.00')
+ expectText(texts, '87.00')
+ expectText(texts, 'Tax 19%')
+ expectText(texts, '148.77')
+ expectText(texts, '931.77')
+ expectText(texts, 'Payment within 14 days')
+ expectText(texts, 'Thank you for your business')
+ })
+
+ it('falls back to the display name when the legal name is empty', () => {
+ const invoice = fullInvoice()
+ invoice.seller.legalName = ''
+ invoice.counterparty.legalName = ''
+ const texts = collectTexts(renderer.buildDocument(invoice, 'en'))
+ expectText(texts, 'Acme Studio')
+ expectText(texts, 'Globex')
+ expectNoText(texts, 'Acme Studio LLC')
+ expectNoText(texts, 'Globex GmbH')
+ })
+
+ it('skips empty optional fields instead of printing blanks', () => {
+ const invoice = fullInvoice()
+ invoice.counterparty = { ...invoice.counterparty, address: '', email: '', phone: '', contactPerson: '', requisites: [] }
+ invoice.seller.bank = { bankName: '', accountNumber: '', iban: '', swift: '', correspondentAccount: '' }
+ invoice.seller.requisites = [{ key: 'empty', label: 'Empty', value: ' ' }]
+ invoice.reference = ''
+ invoice.dueDate = null
+ invoice.periodFrom = null
+ invoice.periodTo = null
+ invoice.terms = ''
+ invoice.notes = ''
+ const texts = collectTexts(renderer.buildDocument(invoice, 'en'))
+ expectNoText(texts, 'PAYMENT DETAILS')
+ expectNoText(texts, 'Empty:')
+ expectNoText(texts, 'Anna Schmidt')
+ expectNoText(texts, 'Hauptstr. 5, Berlin')
+ expectNoText(texts, 'Due date')
+ expectNoText(texts, 'Reference')
+ expectNoText(texts, 'Period')
+ expect(texts.filter(text => text === ' · ')).toHaveLength(0)
+ })
+
+ it('prints the tax note instead of the tax row for a tax-exempt invoice', () => {
+ const invoice = fullInvoice()
+ invoice.taxExempt = true
+ invoice.taxNote = 'VAT not applicable'
+ const texts = collectTexts(renderer.buildDocument(invoice, 'en'))
+ expectText(texts, 'VAT not applicable')
+ expectNoText(texts, 'Tax 19%')
+ })
+
+ it('uses russian labels and a void watermark', () => {
+ const invoice = fullInvoice()
+ invoice.status = 'void'
+ const document = renderer.buildDocument(invoice, 'ru') as { watermark?: { text: string } }
+ const texts = collectTexts(document)
+ expectText(texts, 'СЧЁТ')
+ expectText(texts, 'ПЛАТЕЛЬЩИК')
+ expectText(texts, 'РЕКВИЗИТЫ ДЛЯ ОПЛАТЫ')
+ expectText(texts, 'Налог 19%')
+ expect(document.watermark?.text).toBe('АННУЛИРОВАН')
+ })
+})
diff --git a/api/src/tv-modules/invoices/__tests__/Invoices.integration.spec.ts b/api/src/tv-modules/invoices/__tests__/Invoices.integration.spec.ts
index 3cd3a5c..c4fe24c 100644
--- a/api/src/tv-modules/invoices/__tests__/Invoices.integration.spec.ts
+++ b/api/src/tv-modules/invoices/__tests__/Invoices.integration.spec.ts
@@ -41,11 +41,21 @@ const counterpartyPayload = () => ({
legalName: 'IT Client GmbH',
address: '',
- phone: '',
+ phone: '+49 30 555',
contactPerson: 'Anna',
- requisites: [],
+ requisites: [{ key: 'vat', label: 'USt-IdNr.', value: 'DE999' }],
})
+const expectedSellerSnapshot = () => {
+ const { name, legalName, address, email, phone, logoUrl, bank, requisites } = sellerPayload()
+ return { name, legalName, address, email, phone, logoUrl, bank, requisites }
+}
+
+const expectedCounterpartySnapshot = () => {
+ const { kind, name, legalName, address, email, phone, contactPerson, requisites } = counterpartyPayload()
+ return { kind, name, legalName, address, email, phone, contactPerson, requisites }
+}
+
const invoicePayload = (number: string) => ({
organizationId,
goalId,
@@ -130,8 +140,8 @@ describe('billing and invoices', () => {
invoiceId = invoice.id
expect(invoice.status).toBe('draft')
expect(invoice.goalName).toBe('billing-it-goal')
- expect(invoice.seller.legalName).toBe('IT Seller LLC')
- expect(invoice.counterparty.contactPerson).toBe('Anna')
+ expect(invoice.seller).toEqual(expectedSellerSnapshot())
+ expect(invoice.counterparty).toEqual(expectedCounterpartySnapshot())
expect(invoice.lines).toHaveLength(2)
expect(invoice.lines[1].quantity).toBe(10.5)
expect(invoice.discountValue).toBe(10)
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 4ad8432..3f4ed89 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -126,6 +126,9 @@ importers:
passport-google-oauth20:
specifier: ^2.0.0
version: 2.0.0
+ pdfmake:
+ specifier: ^0.3.11
+ version: 0.3.11
pg:
specifier: 8.20.0
version: 8.20.0
@@ -196,6 +199,9 @@ importers:
'@types/passport-apple':
specifier: ^2.0.3
version: 2.0.3
+ '@types/pdfmake':
+ specifier: ^0.3.3
+ version: 0.3.3
'@types/pg':
specifier: ^8.15.5
version: 8.16.0
@@ -224,6 +230,15 @@ importers:
specifier: ^2.1.1
+ taskview-packages/capacitor-widget-bridge:
+ devDependencies:
+ '@capacitor/core':
+ specifier: ^8.1.0
+ version: 8.1.0
+ typescript:
+ specifier: ~5.8.3
+ version: 5.8.3
+
taskview-packages/taskview-api:
dependencies:
vite-plugin-dts:
@@ -424,6 +439,9 @@ importers:
axios:
specifier: 1.13.5
version: 1.13.5
+ capacitor-widget-bridge:
+ specifier: workspace:^
+ version: link:../taskview-packages/capacitor-widget-bridge
centrifuge:
specifier: ^5.5.3
version: 5.5.3
@@ -439,6 +457,9 @@ importers:
firebase:
specifier: ^12.10.0
version: 12.10.0
+ pdfjs-dist:
+ specifier: ^6.3.289
+ version: 6.3.289
pinia:
specifier: ^2.3.1
@@ -2201,12 +2222,86 @@ packages:
'@cfworker/json-schema':
optional: true
+ '@napi-rs/[email protected]':
+ resolution: {integrity: sha512-4LGXk2/0HVzE29K8SzML5WubgCp++B1FH3qgl35XmSZE+lLdr6P9VRQEnZ0MCLZMTSuJP41yyhtoiVNEuvrTIA==}
+ engines: {node: '>= 10'}
+ cpu: [arm64]
+ os: [android]
+
+ '@napi-rs/[email protected]':
+ resolution: {integrity: sha512-YNdfLBzY0W/Pep9fo2L6RmoNlNksnn05LRnX66W63R3ij58S25QOTcjdtEt2v8+PnCESzqZsYzUo+QPeIR44NA==}
+ engines: {node: '>= 10'}
+ cpu: [arm64]
+ os: [darwin]
+
+ '@napi-rs/[email protected]':
+ resolution: {integrity: sha512-ceZQSknTEcy3dOXoekv59LTCkXjvnLsq+VW5PeNNDHEPQbRS5Ervkm1EaDa7WLAjiYWMLuSQTRTHao1dEX4prg==}
+ engines: {node: '>= 10'}
+ cpu: [x64]
+ os: [darwin]
+
+ '@napi-rs/[email protected]':
+ resolution: {integrity: sha512-XhfI0Wwv4llhd6nnWDtY3kQKjq0r+y1i91PlJlJI24ag2U9WrnwbG1qS3+fDLEyouwEVFchiKkTEHozK+5iUNA==}
+ engines: {node: '>= 10'}
+ cpu: [arm]
+ os: [linux]
+
+ '@napi-rs/[email protected]':
+ resolution: {integrity: sha512-012oiYtKaE7i9oxc8q7nraT7kDOpLcaCmFLzVe9Ty34RHDdoDzbWLrVh827CNxYh/EADX1eSikA3ymLjo/nNuw==}
+ engines: {node: '>= 10'}
+ cpu: [arm64]
+ os: [linux]
+
+ '@napi-rs/[email protected]':
+ resolution: {integrity: sha512-Ls5UWYFFn63casTZEczbeyEg3vRDRkv9lscuGwfchtY5yLLQhgOB8SN4YGxmfJ5vTaBwZ2YUxBS3NtmjJmFXdA==}
+ engines: {node: '>= 10'}
+ cpu: [arm64]
+ os: [linux]
+
+ '@napi-rs/[email protected]':
+ resolution: {integrity: sha512-hLKEGxV7ZiRHqndePTokgDMdBlo/rDfzg7P4p4QIv9pUhuYobnu3R2NIFLCRghG0nwfo+s2sw+c1xZFeCmEAsw==}
+ engines: {node: '>= 10'}
+ cpu: [riscv64]
+ os: [linux]
+
+ '@napi-rs/[email protected]':
+ resolution: {integrity: sha512-6kaz3w0QMy77PDWk6rJ1ksIihdad3qzEyX2o2oGT8GwCaypfT5mhjr8buOO5hstyLxcWXDScuz56RsINLtBPIQ==}
+ engines: {node: '>= 10'}
+ cpu: [x64]
+ os: [linux]
+
+ '@napi-rs/[email protected]':
+ resolution: {integrity: sha512-xrGvmS3v55hmZ86ls/kBLVNMUTYio3f6Ik0DireemG994VfPAwiA3ZXA0Uf1bByctkB3NQ1Sfb+H5bkdUnnzfQ==}
+ engines: {node: '>= 10'}
+ cpu: [x64]
+ os: [linux]
+
+ '@napi-rs/[email protected]':
+ resolution: {integrity: sha512-yjmVS3ArZeRVCP7jqbPq4rpZa/BhTeI7ELE2XqJg3snICQBDevLZyArxswHkiTnT34KRic33/4fLirrHI+SY8A==}
+ engines: {node: '>= 10'}
+ cpu: [arm64]
+ os: [win32]
+
+ '@napi-rs/[email protected]':
+ resolution: {integrity: sha512-QlSYQdMQslB81nlABo9wNfQ6npFhE7/O+saCZdqVGueGanyRk4jCogD5EwQenfP3kIq9e+mm6GreQBjX5MrA8g==}
+ engines: {node: '>= 10'}
+ cpu: [x64]
+ os: [win32]
+
+ '@napi-rs/[email protected]':
+ resolution: {integrity: sha512-QviPdJImDi/jMAvBfqaw+19BndMd/sizXVW3NnpMd3VJGz++QXkOHcP9kWR/smHG0hNjHeyuHFyrx/5lD0oNcQ==}
+ engines: {node: '>= 10'}
+
'@napi-rs/[email protected]':
resolution: {integrity: sha512-sNXv5oLJ7ob93xkZ1XnxisYhGYXfaG9f65/ZgYuAu3qt7b3NadcOEhLvx28hv31PgX8SZJRYrAIPQilQmFpLVw==}
peerDependencies:
'@emnapi/core': ^1.7.1
'@emnapi/runtime': ^1.7.1
+ '@noble/[email protected]':
+ resolution: {integrity: sha512-2I0gnIVPtfnMw9ee9h1dJG7tp81+8Ob3OJb3Mv37rx5L40/b0i7djjCVvGOVqc9AEIQyvyu1i6ypKdFw8R8gQw==}
+ engines: {node: ^14.21.3 || >=16}
+
resolution: {integrity: sha512-jCs9ldd7NwzpgXDIf6P3+NrHh9/sD6CQdxHyjQI+h/6rDNo88ypBxxz45UDuZHz9r3tNz7N/VInSVoVdtXEI4A==}
engines: {node: ^14.21.3 || >=16}
@@ -3374,6 +3469,12 @@ packages:
resolution: {integrity: sha512-j3pOPiEcWZ34R6a6mN07mUkM4o4Lwf6hPNt8eilOeZhTFbxFXmKhvXl9Y28jotFPaI1bpPDJsbCprUoNke6OrA==}
+ '@types/[email protected]':
+ resolution: {integrity: sha512-tIwzxk2uWKp0Cq9JIluQXJid77lYhF52EsIOwhsMF4iWLA6YneoBR1xVKYYdAysHuepUB0OX4tdwMiUDdGKmig==}
+
+ '@types/[email protected]':
+ resolution: {integrity: sha512-ufbceB4Q3dKpmFUMKEbZvJcfLi8+C5b1+rTFVG6urtkS3FHwaTQH6NCh/iEEDINlApCxH/W3/rsq99pP5E9/JA==}
+
resolution: {integrity: sha512-RmhMd/wD+CF8Dfo+cVIy3RR5cl8CyfXQ0tGgW6XBL8L4LM/UTEbNXYRbLwU6w+CgrKBNbrQWt4FUtTfaU5jSYQ==}
@@ -4111,6 +4212,10 @@ packages:
resolution: {integrity: sha512-ZMq4gd9ngV5aTMa5p9+UfY0b3skwhHELaDkhEHetMdX0LRkW9kzaym4oo/Eh+Ghm0CCDuMTsRIGM/ytUc1ZYmw==}
+ resolution: {integrity: sha512-3XSA2cR/h/73EzlXXdU6YNycmYI7+kicTxks4eJg2g39biHR84slg2+des+p7iHYhbRg/udIS4TD53WabcOUkw==}
+ engines: {node: '>= 0.4'}
+
resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==}
@@ -4176,6 +4281,9 @@ packages:
resolution: {integrity: sha512-oTKjJdShmDuGW94SyyaoQvAjf30dZaHnjJ8uAF+u2/vGJkJbJPJAT1gDiOJP5v1Zb6f9KEyW/1HpuaWIXtGHPg==}
+ resolution: {integrity: sha512-Z942RysHXmJrhqk88FmKBVq/v5tqmSkDz7p54G/MGyjMnCFFnC79XWNbg+Vta8W6Wb2qtSZTSxIGkJrRpCFEiA==}
+
resolution: {integrity: sha512-KN+mty6C3e9AN8Z5dI1xeN15ExcRNeISoC3g7V0Kax/MMF9MSoYA2G7lkTTcVUFntiEjkpI0HNgqJC1NjdyNUw==}
engines: {node: '>=18'}
@@ -6020,6 +6128,9 @@ packages:
resolution: {integrity: sha512-d7kPDd34KO/YnzaDOlikGpOurfF0ByC2sEV4cANCtdqLlTfBlw2p14O/5d/zv40gJPbIQxfES3nSx1/oYNyuZQ==}
+ resolution: {integrity: sha512-qR0HB5uP6wCuRMrWPTrkMaev7MJZwJuuw4fnwAzRgP4J4/F8RwtodOKpGp4XpqsLBFzzgqIO42efFAyz2Et6KQ==}
+
resolution: {integrity: sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==}
@@ -6287,6 +6398,9 @@ packages:
resolution: {integrity: sha512-FWWMIEOxz3GwUI4Ts/IvgVy6LPvoMPgjMdQ185nN6psJyBJ4yOpzqm695/h5umdLJg2vW3GR5iG11MAkR2AzJA==}
+ resolution: {integrity: sha512-MHp03UImeVhB7XZtjd0E4n6+3xr5Dq/9xI/5FptGk5FrbDR3zagPa2DS6U8ks/3HjbKWG9Q1M2ufOzxV2qLYSQ==}
+
resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==}
@@ -6813,6 +6927,9 @@ packages:
resolution: {integrity: sha512-NUcwaKxUxWrZLpDG+z/xZaCgQITkA/Dv4V/T6bw7VON6l1Xz/VnrBqrYjZQ12TamKHzITTfOEIYUj48y2KXImA==}
+ resolution: {integrity: sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==}
+
resolution: {integrity: sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==}
engines: {node: '>=6'}
@@ -6924,6 +7041,17 @@ packages:
resolution: {integrity: sha512-XDF38WCH3z5OV/OVa8GKUNtLAyneuzbCisx7QUCF8Q6Nutx0WnJrQe5O+kOtBlLfRNUws98Y58Lblp+NJG5T4Q==}
hasBin: true
+ resolution: {integrity: sha512-ZHjSVpDa3D6izMq8/04lvkhkATUmL9px6ChPaXc1k6nU2Mrhlg1/7F0bdUqCwUjw3NsPTfPZsMDUU6ZIcRaeQw==}
+ engines: {node: '>=22.13.0 || >=24'}
+
+ resolution: {integrity: sha512-6Gzk+wDwTs4VSxsR5rCMTnIl5nlmkye1oWB0l2hDB1EX6ZNSIBroKQEv+2+fPPn+stVjyqzmsqRJVDfB9fo5DA==}
+
+ resolution: {integrity: sha512-Uc49J9hUMyuqJk+U+PxlpBpPr96A4HOOfesGx609EPr2ue82+5/Smq/KTAkEqh0/jUGSi1fumvqZ5yAWijJTJg==}
+ engines: {node: '>=20'}
+
resolution: {integrity: sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==}
@@ -7038,6 +7166,9 @@ packages:
resolution: {integrity: sha512-uysumyrvkUX0rX/dEVqt8gC3sTBzd4zoWfLeS29nb53imdaXVvLINYXTI2GNqzaMuvacNx4uJQ8+b3zXR0pkgQ==}
engines: {node: '>=10.4.0'}
+ resolution: {integrity: sha512-PM/uYGzGdNSzqeOgly68+6wKQDL1SY0a/N+OEa/+br6LnHWOAJB0Npiamnodfq3jd2LS/i2fMeOKSAILjA+m5Q==}
+
resolution: {integrity: sha512-/+5VFTchJDoVj3bhoqi6UeymcD00DAwb1nJwamzPvHEszJ4FpF6SNNbUbOS8yI56qHzdV8eK0qEfOSiodkTdxg==}
engines: {node: '>= 0.4'}
@@ -8738,6 +8869,10 @@ packages:
resolution: {integrity: sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==}
+ resolution: {integrity: sha512-6gRk4NY/Jvg67xn7OzJuxLRsGgiXBaPUQplVJ/9l99uIugxh4FTOewYz5ic8WScj7Xx/2WvhENiQKwkK9RpE4w==}
+ engines: {node: '>=12.0.0'}
+
resolution: {integrity: sha512-fg03WRxtkCV6ohClePNAECYsmpKKTv5L8y/X3Dn1hQrec3POx2jHZ/0P2qQ6HvsrU1BmeqXcof3NGGueG6LxwQ==}
engines: {node: '>=0.6.0'}
@@ -10802,6 +10937,54 @@ snapshots:
transitivePeerDependencies:
- supports-color
+ '@napi-rs/[email protected]':
+ optional: true
+
+ '@napi-rs/[email protected]':
+ optional: true
+
+ '@napi-rs/[email protected]':
+ optional: true
+
+ '@napi-rs/[email protected]':
+ optional: true
+
+ '@napi-rs/[email protected]':
+ optional: true
+
+ '@napi-rs/[email protected]':
+ optional: true
+
+ '@napi-rs/[email protected]':
+ optional: true
+
+ '@napi-rs/[email protected]':
+ optional: true
+
+ '@napi-rs/[email protected]':
+ optional: true
+
+ '@napi-rs/[email protected]':
+ optional: true
+
+ '@napi-rs/[email protected]':
+ optional: true
+
+ '@napi-rs/[email protected]':
+ optionalDependencies:
+ '@napi-rs/canvas-android-arm64': 1.0.9
+ '@napi-rs/canvas-darwin-arm64': 1.0.9
+ '@napi-rs/canvas-darwin-x64': 1.0.9
+ '@napi-rs/canvas-linux-arm-gnueabihf': 1.0.9
+ '@napi-rs/canvas-linux-arm64-gnu': 1.0.9
+ '@napi-rs/canvas-linux-arm64-musl': 1.0.9
+ '@napi-rs/canvas-linux-riscv64-gnu': 1.0.9
+ '@napi-rs/canvas-linux-x64-gnu': 1.0.9
+ '@napi-rs/canvas-linux-x64-musl': 1.0.9
+ '@napi-rs/canvas-win32-arm64-msvc': 1.0.9
+ '@napi-rs/canvas-win32-x64-msvc': 1.0.9
+ optional: true
+
dependencies:
'@emnapi/core': 1.9.1
@@ -10809,6 +10992,8 @@ snapshots:
'@tybys/wasm-util': 0.10.1
optional: true
+ '@noble/[email protected]': {}
+
'@noble/[email protected]': {}
'@node-saml/[email protected]':
@@ -12145,6 +12330,15 @@ snapshots:
'@types/[email protected]': {}
+ '@types/[email protected]':
+ dependencies:
+ '@types/node': 22.19.7
+
+ '@types/[email protected]':
+ dependencies:
+ '@types/node': 22.19.7
+ '@types/pdfkit': 0.17.6
+
dependencies:
'@types/node': 22.19.7
@@ -13102,6 +13296,8 @@ snapshots:
bare-path: 3.0.0
optional: true
+
@@ -13189,6 +13385,10 @@ snapshots:
dependencies:
base64-js: 1.5.1
+ dependencies:
+ pako: 1.0.11
+
dependencies:
browserslist: 4.28.1
@@ -15234,6 +15434,8 @@ snapshots:
+
@@ -15480,6 +15682,11 @@ snapshots:
+ dependencies:
+ base64-js: 0.0.8
+ unicode-trie: 2.0.0
+
@@ -15994,6 +16201,8 @@ snapshots:
+
dependencies:
callsites: 3.1.0
@@ -16096,6 +16305,25 @@ snapshots:
ieee754: 1.2.1
resolve-protobuf-schema: 2.1.0
+ optionalDependencies:
+ '@napi-rs/canvas': 1.0.9
+
+ dependencies:
+ '@noble/ciphers': 1.3.0
+ '@noble/hashes': 1.8.0
+ fontkit: 2.0.4
+ js-md5: 0.8.3
+ linebreak: 1.1.0
+ png-js: 1.1.0
+
+ dependencies:
+ linebreak: 1.1.0
+ pdfkit: 0.19.1
+ xmldoc: 2.0.3
+
@@ -16215,6 +16443,10 @@ snapshots:
base64-js: 1.5.1
xmlbuilder: 15.1.1
+ dependencies:
+ browserify-zlib: 0.2.0
+
@@ -18078,6 +18310,10 @@ snapshots:
optional: true
+ dependencies:
+ sax: 1.4.4
+
diff --git a/web/package.json b/web/package.json
index d6958f5..acb0bcd 100644
--- a/web/package.json
+++ b/web/package.json
@@ -2,7 +2,7 @@
"name": "web-nuxt-ui",
"private": true,
"type": "module",
- "version": "1.53.0",
+ "version": "1.53.4",
"scripts": {
"dev": "vite",
"build:packages": "pnpm --filter taskview-db-schemas build && pnpm --filter taskview-api build && pnpm --filter capacitor-widget-bridge build",
@@ -64,6 +64,7 @@
"chartjs-plugin-annotation": "^3.1.0",
"date-fns": "^4.1.0",
"firebase": "^12.10.0",
+ "pdfjs-dist": "^6.3.289",
"pinia": "^2.3.1",
"qs": "^6.14.1",
"rrule": "^2.8.1",
@@ -92,4 +93,4 @@
"vue-tsc": "^3.2.2"
},
"packageManager": "[email protected]"
-}
+}
\ No newline at end of file
diff --git a/web/src/bootstrap.ts b/web/src/bootstrap.ts
index f41a11a..1ea52cf 100644
--- a/web/src/bootstrap.ts
+++ b/web/src/bootstrap.ts
@@ -1,3 +1,4 @@
+import '@/utils/polyfills'
import './assets/css/main.css'
import { addCollection } from '@iconify/vue'
import lucide from '@iconify-json/lucide/icons.json'
diff --git a/web/src/components/features/invoices/InvoicePdfPages.vue b/web/src/components/features/invoices/InvoicePdfPages.vue
new file mode 100644
index 0000000..273afc5
--- /dev/null
+++ b/web/src/components/features/invoices/InvoicePdfPages.vue
@@ -0,0 +1,63 @@
+<template>
+ <div class="flex min-h-0 flex-col gap-2">
+ <InvoicePdfZoomControls v-model="zoom" />
+ <div
+ ref="viewport"
+ class="min-h-0 flex-1 overflow-auto rounded-lg bg-neutral-100 p-2 dark:bg-neutral-900"
+ data-testid="invoice-pdf-pages"
+ >
+ <p
+ v-if="failed"
+ class="py-16 text-center text-sm text-muted"
+ >
+ {{ t('invoices.preview.pdfFailed') }}
+ </p>
+ <div
+ v-else
+ class="flex w-max min-w-full flex-col items-center gap-3"
+ >
+ <canvas
+ v-for="pageNumber in pageCount"
+ :key="pageNumber"
+ :ref="(el) => setCanvas(pageNumber, el)"
+ class="bg-white shadow-sm"
+ />
+ </div>
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { computed, nextTick, ref, toRef, useTemplateRef, watch } from 'vue'
+import type { ComponentPublicInstance } from 'vue'
+import { useI18n } from 'vue-i18n'
+import { useDebounceFn, useElementSize } from '@vueuse/core'
+import { usePdfPages } from '@/composables/usePdfPages'
+import InvoicePdfZoomControls from '@/components/features/invoices/InvoicePdfZoomControls.vue'
+
+const props = defineProps<{
+ blob: Blob | null
+}>()
+
+const { t } = useI18n()
+
+const viewport = useTemplateRef<HTMLElement>('viewport')
+const { width } = useElementSize(viewport)
+const zoom = ref(1)
+const pageWidth = computed(() => Math.floor(width.value * zoom.value))
+
+const { pageCount, failed, renderPage } = usePdfPages({ blob: toRef(props, 'blob'), pageWidth })
+
+const canvases = new Map<number, HTMLCanvasElement>()
+
+function setCanvas(pageNumber: number, el: Element | ComponentPublicInstance | null) {
+ if (el instanceof HTMLCanvasElement) canvases.set(pageNumber, el)
+ else canvases.delete(pageNumber)
+}
+
+const renderAll = useDebounceFn(async () => {
+ for (const [pageNumber, canvas] of canvases) await renderPage({ pageNumber, canvas })
+}, 100)
+
+watch([pageCount, pageWidth], () => nextTick(renderAll))
+</script>
diff --git a/web/src/components/features/invoices/InvoicePdfViewer.vue b/web/src/components/features/invoices/InvoicePdfViewer.vue
index 9217520..35ddbea 100644
--- a/web/src/components/features/invoices/InvoicePdfViewer.vue
+++ b/web/src/components/features/invoices/InvoicePdfViewer.vue
@@ -10,25 +10,25 @@
/>
</div>
<p
- v-else-if="!url"
+ v-else-if="!blob"
class="py-16 text-center text-sm text-muted"
>
{{ t('invoices.preview.pdfFailed') }}
</p>
- <iframe
+ <InvoicePdfPages
v-else
- :src="url"
- :title="title"
- class="min-h-0 w-full flex-1 rounded-lg bg-white"
+ :blob="blob"
+ class="min-h-0 flex-1"
/>
</div>
</template>
<script setup lang="ts">
-import { onBeforeUnmount, ref, watch } from 'vue'
+import { ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import type { InvoicePdfLang } from 'taskview-api'
import { useInvoicesStore } from '@/stores/invoices.store'
+import InvoicePdfPages from '@/components/features/invoices/InvoicePdfPages.vue'
const props = defineProps<{
invoiceId: number
@@ -43,25 +43,16 @@ const emit = defineEmits<{
const { t, locale } = useI18n()
const invoicesStore = useInvoicesStore()
-const url = ref<string | null>(null)
+const blob = ref<Blob | null>(null)
const loading = ref(false)
-function release() {
- if (url.value) URL.revokeObjectURL(url.value.split('#')[0])
- url.value = null
-}
-
async function load() {
loading.value = true
const lang: InvoicePdfLang = locale.value === 'ru' ? 'ru' : 'en'
- const blob = await invoicesStore.fetchPdf(props.invoiceId, lang)
- release()
- if (blob) url.value = `${URL.createObjectURL(blob)}#navpanes=0&view=FitH`
+ blob.value = await invoicesStore.fetchPdf(props.invoiceId, lang)
loading.value = false
- emit('loaded', blob)
+ emit('loaded', blob.value)
}
watch(() => [props.invoiceId, props.version, locale.value], load, { immediate: true })
-
-onBeforeUnmount(release)
</script>
diff --git a/web/src/components/features/invoices/InvoicePdfZoomControls.vue b/web/src/components/features/invoices/InvoicePdfZoomControls.vue
new file mode 100644
index 0000000..8d0a9b1
--- /dev/null
+++ b/web/src/components/features/invoices/InvoicePdfZoomControls.vue
@@ -0,0 +1,51 @@
+<template>
+ <div class="flex items-center justify-end gap-1">
+ <UButton
+ icon="i-lucide-zoom-out"
+ :aria-label="t('invoices.preview.zoomOut')"
+ color="neutral"
+ variant="ghost"
+ size="sm"
+ :disabled="model <= ZOOM_STEPS[0]"
+ data-testid="invoice-pdf-zoom-out"
+ @click="step(-1)"
+ />
+ <UButton
+ :label="`${Math.round(model * 100)}%`"
+ :aria-label="t('invoices.preview.fitWidth')"
+ color="neutral"
+ variant="ghost"
+ size="sm"
+ class="min-w-14 justify-center tabular-nums"
+ data-testid="invoice-pdf-fit-width"
+ @click="model = 1"
+ />
+ <UButton
+ icon="i-lucide-zoom-in"
+ :aria-label="t('invoices.preview.zoomIn')"
+ color="neutral"
+ variant="ghost"
+ size="sm"
+ :disabled="model >= ZOOM_STEPS[ZOOM_STEPS.length - 1]"
+ data-testid="invoice-pdf-zoom-in"
+ @click="step(1)"
+ />
+ </div>
+</template>
+
+<script setup lang="ts">
+import { useI18n } from 'vue-i18n'
+
+const ZOOM_STEPS = [0.5, 0.75, 1, 1.25, 1.5, 2, 3]
+
+const model = defineModel<number>({ required: true })
+
+const { t } = useI18n()
+
+function step(direction: 1 | -1) {
+ const index = ZOOM_STEPS.findIndex(value => value >= model.value)
+ const current = index === -1 ? ZOOM_STEPS.length - 1 : index
+ const next = ZOOM_STEPS[Math.min(ZOOM_STEPS.length - 1, Math.max(0, current + direction))]
+ if (next !== undefined) model.value = next
+}
+</script>
diff --git a/web/src/components/features/invoices/InvoicesListItem.vue b/web/src/components/features/invoices/InvoicesListItem.vue
index 6021c5a..dc274d4 100644
--- a/web/src/components/features/invoices/InvoicesListItem.vue
+++ b/web/src/components/features/invoices/InvoicesListItem.vue
@@ -1,7 +1,7 @@
<template>
<button
type="button"
- class="flex w-full flex-wrap items-center gap-x-3 gap-y-1 rounded-lg border border-default px-4 py-3 text-left hover:bg-elevated"
+ class="flex w-full cursor-pointer flex-wrap items-center gap-x-3 gap-y-1 rounded-2xl px-4 py-3 text-left shadow-sm transition-colors hover:bg-elevated dark:bg-tv-ui-bg-elevated dark:hover:bg-accented/60"
@click="emit('open', invoice)"
>
<UIcon
diff --git a/web/src/components/features/invoices/PartyListItem.vue b/web/src/components/features/invoices/PartyListItem.vue
index c4c0a86..a8d0cc0 100644
--- a/web/src/components/features/invoices/PartyListItem.vue
+++ b/web/src/components/features/invoices/PartyListItem.vue
@@ -1,5 +1,12 @@
<template>
- <div class="flex w-full flex-wrap items-center gap-x-3 gap-y-1 rounded-lg border border-default px-4 py-3">
+ <div
+ role="button"
+ tabindex="0"
+ class="flex w-full cursor-pointer flex-wrap items-center gap-x-3 gap-y-1 rounded-2xl px-4 py-3 shadow-sm transition-colors hover:bg-elevated focus-visible:outline-2 focus-visible:outline-primary dark:bg-tv-ui-bg-elevated dark:hover:bg-accented/60"
+ @click="emit('edit')"
+ @keydown.enter.prevent="emit('edit')"
+ @keydown.space.prevent="emit('edit')"
+ >
<UIcon
:name="icon"
class="size-5 shrink-0 text-muted"
@@ -17,7 +24,10 @@
</span>
<span class="truncate text-xs text-muted">{{ subtitle }}</span>
</div>
- <div class="ml-auto flex items-center">
+ <div
+ class="ml-auto flex items-center"
+ @click.stop
+ >
<UButton
icon="i-lucide-pencil"
color="neutral"
diff --git a/web/src/composables/usePdfPages.ts b/web/src/composables/usePdfPages.ts
new file mode 100644
index 0000000..f3906ec
--- /dev/null
+++ b/web/src/composables/usePdfPages.ts
@@ -0,0 +1,83 @@
+import { onBeforeUnmount, ref, shallowRef, watch } from 'vue'
+import * as pdfjs from 'pdfjs-dist/legacy/build/pdf.mjs'
+import type { PDFDocumentLoadingTask, PDFDocumentProxy, RenderTask } from 'pdfjs-dist/legacy/build/pdf.mjs'
+import pdfWorkerUrl from 'pdfjs-dist/legacy/build/pdf.worker.min.mjs?url'
+import type { RenderPdfPageArgs, UsePdfPagesArgs } from '@/composables/usePdfPages.types'
+
+pdfjs.GlobalWorkerOptions.workerSrc = pdfWorkerUrl
+
+export function usePdfPages({ blob, pageWidth }: UsePdfPagesArgs) {
+ const document = shallowRef<PDFDocumentProxy | null>(null)
+ let loadingTask: PDFDocumentLoadingTask | null = null
+ const pageCount = ref(0)
+ const failed = ref(false)
+ const tasks = new Map<number, RenderTask>()
+ const generations = new Map<number, number>()
+
+ function cancelAll() {
+ tasks.forEach(task => task.cancel())
+ tasks.clear()
+ }
+
+ async function open(source: Blob | null) {
+ cancelAll()
+ const previous = loadingTask
+ loadingTask = null
+ document.value = null
+ pageCount.value = 0
+ failed.value = false
+ await previous?.destroy()
+ if (!source) return
+ try {
+ const task = pdfjs.getDocument({ data: await source.arrayBuffer() })
+ loadingTask = task
+ const loaded = await task.promise
+ if (loadingTask !== task) {
+ await task.destroy()
+ return
+ }
+ document.value = loaded
+ pageCount.value = loaded.numPages
+ } catch {
+ failed.value = true
+ }
+ }
+
+ async function renderPage({ pageNumber, canvas }: RenderPdfPageArgs) {
+ const loaded = document.value
+ if (!loaded || pageWidth.value <= 0) return
+ const generation = (generations.get(pageNumber) ?? 0) + 1
+ generations.set(pageNumber, generation)
+ tasks.get(pageNumber)?.cancel()
+
+ const page = await loaded.getPage(pageNumber)
+ if (document.value !== loaded || generations.get(pageNumber) !== generation) return
+
+ const base = page.getViewport({ scale: 1 })
+ const viewport = page.getViewport({ scale: pageWidth.value / base.width })
+ const dpr = window.devicePixelRatio || 1
+ canvas.width = Math.floor(viewport.width * dpr)
+ canvas.height = Math.floor(viewport.height * dpr)
+ canvas.style.width = `${Math.floor(viewport.width)}px`
+ canvas.style.height = `${Math.floor(viewport.height)}px`
+
+ const task = page.render({ canvas, viewport, transform: dpr === 1 ? undefined : [dpr, 0, 0, dpr, 0, 0] })
+ tasks.set(pageNumber, task)
+ try {
+ await task.promise
+ } catch (error) {
+ if (!(error instanceof pdfjs.RenderingCancelledException)) throw error
+ } finally {
+ if (tasks.get(pageNumber) === task) tasks.delete(pageNumber)
+ }
+ }
+
+ watch(blob, open, { immediate: true })
+
+ onBeforeUnmount(() => {
+ cancelAll()
+ loadingTask?.destroy()
+ })
+
+ return { pageCount, failed, renderPage }
+}
diff --git a/web/src/composables/usePdfPages.types.ts b/web/src/composables/usePdfPages.types.ts
new file mode 100644
index 0000000..c6a6d08
--- /dev/null
+++ b/web/src/composables/usePdfPages.types.ts
@@ -0,0 +1,11 @@
+import type { Ref } from 'vue'
+
+export type UsePdfPagesArgs = {
+ blob: Ref<Blob | null>
+ pageWidth: Ref<number>
+}
+
+export type RenderPdfPageArgs = {
+ pageNumber: number
+ canvas: HTMLCanvasElement
+}
diff --git a/web/src/locales/de.ts b/web/src/locales/de.ts
index f966175..7222186 100644
--- a/web/src/locales/de.ts
+++ b/web/src/locales/de.ts
@@ -1242,6 +1242,9 @@ export default {
preview: {
download: 'PDF herunterladen',
pdfFailed: 'PDF konnte nicht erstellt werden',
+ zoomIn: 'Vergrößern',
+ zoomOut: 'Verkleinern',
+ fitWidth: 'An Breite anpassen',
back: 'Zur Liste',
notFound: 'Rechnung nicht gefunden',
},
diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts
index 9f43b2d..5f04be1 100644
--- a/web/src/locales/en.ts
+++ b/web/src/locales/en.ts
@@ -1256,6 +1256,9 @@ export default {
preview: {
download: 'Download PDF',
pdfFailed: 'Could not render the PDF',
+ zoomIn: 'Zoom in',
+ zoomOut: 'Zoom out',
+ fitWidth: 'Fit to width',
back: 'Back to list',
notFound: 'Invoice not found',
},
diff --git a/web/src/locales/es.ts b/web/src/locales/es.ts
index f6b36a8..cd8a3b9 100644
--- a/web/src/locales/es.ts
+++ b/web/src/locales/es.ts
@@ -1242,6 +1242,9 @@ export default {
preview: {
download: 'Descargar PDF',
pdfFailed: 'No se pudo generar el PDF',
+ zoomIn: 'Acercar',
+ zoomOut: 'Alejar',
+ fitWidth: 'Ajustar al ancho',
back: 'Volver a la lista',
notFound: 'Factura no encontrada',
},
diff --git a/web/src/locales/pt-br.ts b/web/src/locales/pt-br.ts
index 8a90f02..509003d 100644
--- a/web/src/locales/pt-br.ts
+++ b/web/src/locales/pt-br.ts
@@ -1253,6 +1253,9 @@ export default {
preview: {
download: 'Baixar PDF',
pdfFailed: 'Não foi possível gerar o PDF',
+ zoomIn: 'Aproximar',
+ zoomOut: 'Afastar',
+ fitWidth: 'Ajustar à largura',
back: 'Voltar à lista',
notFound: 'Fatura não encontrada',
},
diff --git a/web/src/locales/ru.ts b/web/src/locales/ru.ts
index 64fff3b..534622e 100644
--- a/web/src/locales/ru.ts
+++ b/web/src/locales/ru.ts
@@ -1189,6 +1189,9 @@ export default {
preview: {
download: 'Скачать PDF',
pdfFailed: 'Не удалось собрать PDF',
+ zoomIn: 'Увеличить',
+ zoomOut: 'Уменьшить',
+ fitWidth: 'По ширине',
back: 'К списку',
notFound: 'Инвойс не найден',
},
diff --git a/web/src/utils/polyfills.ts b/web/src/utils/polyfills.ts
new file mode 100644
index 0000000..3752a59
--- /dev/null
+++ b/web/src/utils/polyfills.ts
@@ -0,0 +1,21 @@
+type PromiseWithResolvers = <T>() => {
+ promise: Promise<T>
+ resolve: (value: T | PromiseLike<T>) => void
+ reject: (reason?: unknown) => void
+}
+
+const promiseConstructor = Promise as PromiseConstructor & { withResolvers?: PromiseWithResolvers }
+
+if (typeof promiseConstructor.withResolvers !== 'function') {
+ promiseConstructor.withResolvers = <T>() => {
+ let resolve!: (value: T | PromiseLike<T>) => void
+ let reject!: (reason?: unknown) => void
+ const promise = new Promise<T>((res, rej) => {
+ resolve = res
+ reject = rej
+ })
+ return { promise, resolve, reject }
+ }
+}
+
+export {}