feat(core): Enhance document generation capabilities with improved modular structure and extended translation support.

This commit is contained in:
2024-12-01 23:04:28 +01:00
parent ab2c1e21f2
commit 4c9b2671a9
23 changed files with 104 additions and 78 deletions

View File

@ -15,7 +15,7 @@ import {
domtools,
} from '@design.estate/dees-element';
import * as plugins from '../plugins.js';
import * as shared from './shared/index.js';
import * as shared from '../../ts/shared/index.js';

View File

@ -1,4 +1,4 @@
import * as shared from './shared/index.js';
import * as shared from '../../ts/shared/index.js';
import { html } from '@design.estate/dees-element';
export const demoFunc = () => html`

View File

@ -24,7 +24,7 @@ export const defaultDocumentSettings: interfaces.IDocumentSettings = {
import { DePage } from './page.js';
import { DeContentInvoice } from './contentinvoice.js';
import * as shared from './shared/index.js';
import * as shared from '../../ts/shared/index.js';
import { demoFunc } from './document.demo.js';
declare global {

View File

@ -8,4 +8,4 @@ export * from './pagefooter.js';
export * from './pageheader.js';
export * from './viewer.js';
export * from './shared/index.js';
export * from '../../ts/shared/index.js';

View File

@ -10,7 +10,7 @@ import {
} from '@design.estate/dees-element';
import * as domtools from '@design.estate/dees-domtools';
import * as shared from './shared/index.js';
import * as shared from '../../ts/shared/index.js';
import * as tsclass from '@tsclass/tsclass';
declare global {

View File

@ -15,7 +15,7 @@ import * as interfaces from '../../ts/interfaces/index.js';
import { defaultDocumentSettings } from './document.js';
import * as shared from './shared/index.js';
import * as shared from '../../ts/shared/index.js';
declare global {
interface HTMLElementTagNameMap {

View File

@ -10,7 +10,7 @@ import {
} from '@design.estate/dees-element';
import * as domtools from '@design.estate/dees-domtools';
import * as shared from './shared/index.js';
import * as shared from '../../ts/shared/index.js';
declare global {
interface HTMLElementTagNameMap {

View File

@ -10,7 +10,7 @@ import {
} from '@design.estate/dees-element';
import * as domtools from '@design.estate/dees-domtools';
import * as shared from './shared/index.js';
import * as shared from '../../ts/shared/index.js';
import * as tsclass from '@tsclass/tsclass';
declare global {

View File

@ -10,7 +10,7 @@ import {
} from '@design.estate/dees-element';
import * as domtools from '@design.estate/dees-domtools';
import * as shared from './shared/index.js';
import * as shared from '../../ts/shared/index.js';
import * as tsclass from '@tsclass/tsclass';
declare global {

View File

@ -10,7 +10,7 @@ import {
} from '@design.estate/dees-element';
import * as domtools from '@design.estate/dees-domtools';
import * as shared from './shared/index.js';
import * as shared from '../../ts/shared/index.js';
import * as tsclass from '@tsclass/tsclass';
declare global {

View File

@ -1,210 +0,0 @@
import * as tsclass from '@tsclass/tsclass';
const fromContact: tsclass.business.IContact = {
name: 'Awesome From Company',
type: 'company',
description: 'a company that does stuff',
address: {
streetName: 'Awesome Street',
houseNumber: '5',
city: 'Bremen',
country: 'Germany',
postalCode: '28359',
},
vatId: 'DE12345678',
sepaConnection: {
bic: 'BPOTBEB1',
iban: 'BE01234567891616'
},
email: 'hello@awesome.company',
phone: '+49 421 1234567',
fax: '+49 421 1234568',
};
const toContact: tsclass.business.IContact = {
name: 'Awesome To GmbH',
type: 'company',
customerNumber: 'LL-CLIENT-123',
description: 'a company that does stuff',
address: {
streetName: 'Awesome Street',
houseNumber: '5',
city: 'Bremen',
country: 'Germany',
postalCode: '28359'
},
vatId: 'BE12345678',
}
export const demoLetter: tsclass.business.ILetter = {
versionInfo: {
type: 'draft',
version: '1.0.0',
},
accentColor: null,
content: {
textData: null,
timesheetData: null,
contractData: {
contractDate: Date.now(),
id: 'someid'
},
invoiceData: {
id: 'LL-INV-48765',
reverseCharge: true,
dueInDays: 30,
billedBy: fromContact,
billedTo: toContact,
status: null,
deliveryDate: new Date().getTime(),
periodOfPerformance: null,
printResult: null,
currency: 'EUR',
notes: [],
type: 'debitnote',
items: [
{
name: 'Item with 19% VAT',
unitQuantity: 2,
unitNetPrice: 100,
unitType: 'hours',
vatPercentage: 19,
position: 0,
},
{
name: 'Item with 7% VAT',
unitQuantity: 4,
unitNetPrice: 100,
unitType: 'hours',
vatPercentage: 7,
position: 1,
},
{
name: 'Item with 7% VAT',
unitQuantity: 3,
unitNetPrice: 230,
unitType: 'hours',
vatPercentage: 7,
position: 2,
},
{
name: 'Item with 21% VAT',
unitQuantity: 1,
unitNetPrice: 230,
unitType: 'hours',
vatPercentage: 21,
position: 3,
},
{
name: 'Item with 0% VAT',
unitQuantity: 6,
unitNetPrice: 230,
unitType: 'hours',
vatPercentage: 0,
position: 4,
},{
name: 'Item with 19% VAT',
unitQuantity: 8,
unitNetPrice: 100,
unitType: 'hours',
vatPercentage: 19,
position: 5,
},
{
name: 'Item with 7% VAT',
unitQuantity: 9,
unitNetPrice: 100,
unitType: 'hours',
vatPercentage: 7,
position: 6,
},
{
name: 'Item with 7% VAT',
unitQuantity: 4,
unitNetPrice: 230,
unitType: 'hours',
vatPercentage: 7,
position: 8,
},
{
name: 'Item with 21% VAT',
unitQuantity: 3,
unitNetPrice: 230,
unitType: 'hours',
vatPercentage: 21,
position: 9,
},
{
name: 'Item with 0% VAT',
unitQuantity: 1,
unitNetPrice: 230,
unitType: 'hours',
vatPercentage: 0,
position: 10,
},
{
name: 'Item with 0% VAT',
unitQuantity: 1,
unitNetPrice: 230,
unitType: 'hours',
vatPercentage: 0,
position: 10,
},
{
name: 'Item with 0% VAT',
unitQuantity: 1,
unitNetPrice: 230,
unitType: 'hours',
vatPercentage: 0,
position: 10,
},
{
name: 'Item with 0% VAT',
unitQuantity: 1,
unitNetPrice: 230,
unitType: 'hours',
vatPercentage: 0,
position: 10,
},
{
name: 'Item with 0% VAT',
unitQuantity: 1,
unitNetPrice: 230,
unitType: 'hours',
vatPercentage: 0,
position: 10,
},
{
name: 'Item with 0% VAT',
unitQuantity: 1,
unitNetPrice: 230,
unitType: 'hours',
vatPercentage: 0,
position: 10,
},
{
name: 'Item with 0% VAT',
unitQuantity: 1,
unitNetPrice: 230,
unitType: 'hours',
vatPercentage: 0,
position: 10,
},
],
}
},
date: Date.now(),
type: 'invoice',
needsCoverSheet: false,
objectActions: [],
pdf: null,
from: fromContact,
to: toContact,
incidenceId: null,
language: null,
legalContact: null,
logoUrl: null,
pdfAttachments: null,
subject: 'Invoice: LL-INV-48765',
}

View File

@ -1,9 +0,0 @@
export const a4Height = 1122;
export const a4Width = 794;
export const rightMargin = 70;
export const leftMargin = 90;
import * as translation from './translation.js';
export { translation };
export * from './demoletter.js';

View File

@ -1,31 +0,0 @@
import * as interfaces from '../../../ts/interfaces/index.js';
type TTranslationImplementation = {
[key in keyof interfaces.IDeDocumentTranslations]: string;
}
export const EN_translations: TTranslationImplementation = {
invoice: 'Invoice',
quantity: 'Quantity',
};
export const DE_translations: TTranslationImplementation = {
invoice: 'Rechnung',
quantity: 'Anzahl',
};
export const languageCodeMap = {
'DE': DE_translations,
'EN': EN_translations,
};
export type TLanguageCode = keyof typeof languageCodeMap;
export const translate = (languageCode: TLanguageCode, key: string, defaultValue: string) => {
const translations = languageCodeMap[languageCode] || EN_translations;
if (translations && translations[key]) {
return translations[key];
} else {
return defaultValue;
}
};

View File

@ -1,6 +1,6 @@
import { html } from '@design.estate/dees-element';
import * as shared from './shared/index.js';
import * as shared from '../../ts/shared/index.js';
export const demoFunc = () => html`
<dedocument-viewer .letterData=${shared.demoLetter}></dedocument-viewer>
<dedocument-viewer .letterData=${shared.demoLetter} .documentSettings=${shared.demoDocumentSettings}></dedocument-viewer>
`;

View File

@ -1,7 +1,9 @@
import * as plugins from '../plugins.js';
import * as interfaces from '../../ts/interfaces/index.js';
import { DeesElement, css, cssManager, customElement, html } from '@design.estate/dees-element';
import { demoFunc } from './viewer.demo.js';
import { defaultDocumentSettings } from './document.js';
declare global {
interface HTMLElementTagNameMap {
@ -17,6 +19,8 @@ export class DeDocumentViewer extends DeesElement {
// INSTANCE
public letterData: plugins.tsclass.business.ILetter = null;
public documentSettings: interfaces.IDocumentSettings = defaultDocumentSettings;
public static styles = [
cssManager.defaultStyles,
css`
@ -67,7 +71,7 @@ export class DeDocumentViewer extends DeesElement {
<div class="maincontainer">
<div class="viewport">
${this.letterData
? html` <dedocument-dedocument .letterData=${this.letterData}></dedocument-dedocument> `
? html` <dedocument-dedocument .letterData=${this.letterData} .documentSettings=${this.documentSettings}></dedocument-dedocument> `
: html``}
</div>
<div class="controls"></div>