refactored translations, preparing sending of document

This commit is contained in:
2025-07-17 13:03:49 +02:00
parent 7616aa9581
commit dc8de9707a
38 changed files with 430 additions and 390 deletions
+14 -14
View File
@@ -43,7 +43,7 @@
var resp = await fetch(url,{ credentials: 'include'});
if (resp.ok){
const types = await resp.json();
docType = t('document.type_'+types[document.type]);
docType = t('type_'+types[document.type]);
} else {
error = await resp.text();
}
@@ -97,49 +97,49 @@
<span class="error">{error}</span>
{/if}
{#if docType}
<legend>{t('document.add_new',docType)}</legend>
<legend>{t('add_new',docType)}</legend>
{/if}
{#if company}
Company: {company.name}
<fieldset>
<legend>{t('document.customer')}</legend>
<ContactSelector caption={t('document.select_customer')} onselect={contactSelected} />
<legend>{t('customer')}</legend>
<ContactSelector caption={t('select_customer')} onselect={contactSelected} />
<label>
<textarea bind:value={document.customer.name}></textarea>
{t('document.customer_address')}
{t('customer_address')}
</label>
<label>
<input bind:value={document.customer.tax_id} />
{t('document.tax_id')}
{t('tax_id')}
</label>
<label>
<input bind:value={document.customer.id} />
{t('document.customer_id')}
{t('customer_id')}
</label>
<label>
<input bind:value={document.customer.email} />
{t('document.email')}
{t('email')}
</label>
</fieldset>
{/if}
<fieldset>
<legend>{t('document.sender')}</legend>
<legend>{t('sender')}</legend>
<label>
<textarea bind:value={document.sender.name}></textarea>
{t('document.sender_name')}
{t('sender_name')}
</label>
<label>
<input bind:value={document.sender.tax_id} />
{t('document.sender_tax_id')}
{t('sender_tax_id')}
</label>
<label>
<textarea bind:value={document.sender.bank_account}></textarea>
{t('document.sender_bank_account')}
{t('sender_bank_account')}
</label>
<label>
<input bind:value={document.sender.court} />
{t('document.sender_local_court')}
{t('sender_local_court')}
</label>
</fieldset>
<button onclick={submit}>{t('document.create_new')}</button>
<button onclick={submit}>{t('create_new')}</button>
</fieldset>
@@ -35,7 +35,7 @@
</style>
<div>
<h1>{t('task.estimated_times')}</h1>
<h1>{t('estimated_times')}</h1>
{#if error}
<span class="error">{error}</span>
{/if}
+1 -1
View File
@@ -28,7 +28,7 @@
</script>
<div>
<h1>{t('items.items')}</h1>
<h1>{t('items')}</h1>
{#if error}
<span class="error">{error}</span>
{/if}
+14 -14
View File
@@ -45,7 +45,7 @@
}
async function deleteDoc(ev,doc){
if (confirm(t('document.really_delete',doc.number))){
if (confirm(t('really_delete',doc.number))){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${doc.id}`;
const resp = await fetch(url,{
credentials: 'include',
@@ -63,12 +63,12 @@
</script>
<fieldset>
<legend>{selected_company ? t( 'document.list_of',selected_company.name) : t('document.list')}</legend>
<legend>{selected_company ? t( 'list_of',selected_company.name) : t('document.list')}</legend>
{#if error}
<div class="error">{error}</div>
{/if}
<div>
{t('document.select_company')}
{t('select_company')}
{#each Object.entries(companies) as [id,company]}
<button onclick={() => load(company)}>{company.name}</button>
{/each}
@@ -77,15 +77,15 @@
<table>
<thead>
<tr>
<th>{t('document.number')}</th>
<th>{t('document.date')}</th>
<th>{t('document.customer')}</th>
<th>{t('document.gross_sum')}</th>
<th>{t('document.type')}</th>
<th>{t('document.state')}</th>
<th>{t('number')}</th>
<th>{t('date')}</th>
<th>{t('customer')}</th>
<th>{t('gross_sum')}</th>
<th>{t('type')}</th>
<th>{t('state')}</th>
<th>
{t('document.actions')}
<TypeSelector caption={t('document.create_new')} bind:value={docType} onchange={createDoc} />
{t('actions')}
<TypeSelector caption={t('create_new_document')} bind:value={docType} onchange={createDoc} />
</th>
</tr>
</thead>
@@ -96,11 +96,11 @@
<td onclick={() => show(id)}>{document.date}</td>
<td onclick={() => show(id)}>{document.customer.name.split('\n')[0]}</td>
<td onclick={() => show(id)}>{document.sum/100 + document.currency}</td>
<td onclick={() => show(id)}>{t('document.type_'+document.type)}</td>
<td onclick={() => show(id)}>{t('document.state_'+document.state.name)}</td>
<td onclick={() => show(id)}>{t('type_'+document.type)}</td>
<td onclick={() => show(id)}>{t('state_'+document.state.name)}</td>
<td>
{#if document.state.id == 1}
<button onclick={(ev) => deleteDoc(ev,document)}>{t('document.delete')}</button>
<button onclick={(ev) => deleteDoc(ev,document)}>{t('delete')}</button>
{/if}
</td>
</tr>
@@ -1,7 +1,6 @@
<script>
import { useTinyRouter } from 'svelte-tiny-router';
import { onMount } from 'svelte';
import { t } from '../../translations.svelte.js';
import LineEditor from '../../Components/LineEditor.svelte';
import MarkdownEditor from '../../Components/MarkdownEditor.svelte';
import PriceEditor from '../../Components/PriceEditor.svelte';
@@ -30,7 +30,7 @@
}
async function drop(number){
let confirmed = confirm(t('document.confirm_deletion').replace('{pos}',document.positions[number].item));
let confirmed = confirm(t('confirm_deletion').replace('{pos}',document.positions[number].item));
if (!confirmed) return;
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${document.id}/position`;
const resp = await fetch(url,{
@@ -50,14 +50,14 @@
<table class="positions">
<thead>
<tr>
<th>{t('document.pos')}</th>
<th>{t('document.code')}</th>
<th>{t('document.title_or_desc')}</th>
<th>{t('document.amount')}</th>
<th>{t('document.unit')}</th>
<th>{t('document.unit_price')}</th>
<th>{t('document.net_price')}</th>
<th>{t('document.tax_rate')}</th>
<th>{t('pos')}</th>
<th>{t('code')}</th>
<th>{t('title_or_desc')}</th>
<th>{t('amount')}</th>
<th>{t('unit')}</th>
<th>{t('unit_price')}</th>
<th>{t('net_price')}</th>
<th>{t('tax_rate')}</th>
</tr>
</thead>
<tbody>
@@ -66,9 +66,9 @@
{/each}
<tr class="sums">
<td colspan="2"></td>
<td>{t('document.net_sum')}</td>
<td>{t('net_sum')}</td>
<td>{document.net_sum/100}&nbsp;{document.currency}</td>
<td colspan="2">{t('document.gros_sum')}</td>
<td colspan="2">{t('gros_sum')}</td>
<td>{document.gross_sum/100}&nbsp;{document.currency}</td>
<td></td>
</tr>
@@ -19,7 +19,7 @@
title:estimate.name,
description:estimate.description.source,
amount:estimate.estimated_time,
unit:t('document.hours')
unit:t('hours')
});
}
@@ -37,11 +37,11 @@
function timeSelected(time){
select({
item_code:t('document.timetrack'),
item_code:t('timetrack'),
title:time.subject,
description:time.description.source,
amount:time.duration,
unit:t('document.hours'),
unit:t('hours'),
time_id:time.id
});
}
@@ -66,10 +66,10 @@
<div class="position_selector">
<span class="tabs">
<button onclick={() => source=0}>{t('document.items')}</button>
<button onclick={() => source=1}>{t('document.estimated_times')}</button>
<button onclick={() => source=2}>{t('document.timetrack')}</button>
<button onclick={close}>{t('document.abort')}</button>
<button onclick={() => source=0}>{t('items')}</button>
<button onclick={() => source=1}>{t('estimated_times')}</button>
<button onclick={() => source=2}>{t('timetrack')}</button>
<button onclick={close}>{t('abort')}</button>
</span>
{#if source == 0}
<ItemList company_id={doc.company.id} onSelect={itemSelected} />
+24
View File
@@ -0,0 +1,24 @@
<script>
import { onMount } from 'svelte';
import { t } from '../../translations.svelte.js';
import { useTinyRouter } from 'svelte-tiny-router';
const router = useTinyRouter();
let { id } = $props();
let error = $state(null);
</script>
{#if error}
<span class="error">{error}</span>
{/if}
<fieldset>
<legend>{t('customer_email')}</legend>
</fieldset>
<fieldset>
<legend>{t('content')}</legend>
</fieldset>
<fieldset>
<legend>{t('actions')}</legend>
</fieldset>
@@ -1,9 +1,9 @@
<script>
import {onMount} from 'svelte';
import {t} from '../../translations.svelte.js';
let { caption = t('document.select_state'), selected = $bindable(0), onchange = (val) => console.log('changed to '+val)} = $props();
let { caption = t('select_state'), selected = $bindable(0), onchange = (val) => console.log('changed to '+val)} = $props();
let message = $state(t('document.loading'));
let message = $state(t('loading'));
let states = $state(null);
async function loadStates(){
@@ -22,7 +22,7 @@
{#if states}
<select bind:value={selected} onchange={() => onchange(selected)}>
{#each Object.entries(states) as [k,s]}
<option value={+k}>{t('document.state_'+s.toLowerCase())}</option>
<option value={+k}>{t('state_'+s.toLowerCase())}</option>
{/each}
</select>
{:else}
@@ -2,7 +2,7 @@
import {onMount} from 'svelte';
import {t} from '../../translations.svelte.js';
let { caption, company, value = $bindable(0), onchange = () => console.log('changed')} = $props();
let message = t('document.loading');
let message = t('loading');
let templates = $state(null);
async function loadTemplates(){
@@ -22,7 +22,7 @@
<select bind:value onchange={onchange}>
<option value={0}>{caption}</option>
{#each Object.entries(types) as [id,type]}
<option value={id}>{t('document.type_'+type)}</option>
<option value={id}>{t('type_'+type)}</option>
{/each}
</select>
{:else}
+62 -42
View File
@@ -9,9 +9,14 @@
import PositionSelector from './PositionSelector.svelte';
import StateSelector from './StateSelector.svelte';
import TemplateSelector from './TemplateSelector.svelte';
const router = useTinyRouter();
let { id } = $props();
let error = $state(null);
let doc = $state(null);
let pdfDisabled = $state(false);
let sndDisabled = $state(false);
let position_select = $state(false);
let editable = $derived(doc.state == 1);
@@ -30,8 +35,8 @@
async function changeState(newVal){
let success = false;
if (doc.state == 1 || confirm(t('document.confirm_state'))){
success = await submit('state',newVal);
if (doc.state == 1 || confirm(t('confirm_state'))){
success = await update('state',newVal);
}
if (success) {
doc.state = newVal;
@@ -42,7 +47,7 @@
}
}
async function submit(path,newValue){
async function update(path,newValue){
const parts = path.split('.');
if (parts.length<1) return false;
let data = newValue;
@@ -79,9 +84,24 @@
}
}
async function render(){
async function render(ev){
pdfDisabled = true;
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${doc.id}/pdf`;
location.href = url;
const resp = await fetch(url,{credentials:'include'});
if (resp.ok){
error = null;
const blob = await resp.blob();
const parts = resp.headers.get("Content-disposition").split(";");
const filename = parts[1].split('=')[1].split('"').join('');
var fileLink = document.createElement('a');
fileLink.href = URL.createObjectURL(blob);
fileLink.download = filename;
fileLink.click();
} else {
error = await resp.text();
}
pdfDisabled = false;
}
onMount(loadDoc);
@@ -93,90 +113,90 @@
{#if doc}
<fieldset class="customer">
<legend>{t('document.customer')}</legend>
<legend>{t('customer')}</legend>
<table>
<tbody>
<tr>
<td colspan="2">
<MultilineEditor bind:value={doc.customer.name} editable={editable} onSet={(val) => submit('customer.name',val)} />
<MultilineEditor bind:value={doc.customer.name} editable={editable} onSet={(val) => update('customer.name',val)} />
</td>
</tr>
<tr>
<th>{t('document.customer_id')}:</th>
<th>{t('customer_id')}:</th>
<td>
<LineEditor bind:value={doc.customer.id} editable={editable} onSet={(val) => submit('customer.id',val)} />
<LineEditor bind:value={doc.customer.id} editable={editable} onSet={(val) => update('customer.id',val)} />
</td>
</tr>
<tr>
<th>{t('document.tax_id')}:</th>
<th>{t('tax_id')}:</th>
<td>
<LineEditor bind:value={doc.customer.tax_id} editable={editable} onSet={(val) => submit('customer.tax_id',val)} />
<LineEditor bind:value={doc.customer.tax_id} editable={editable} onSet={(val) => update('customer.tax_id',val)} />
</td>
</tr>
<tr>
<th>{t('document.email')}:</th>
<th>{t('email')}:</th>
<td>
<LineEditor bind:value={doc.customer.email} editable={editable} onSet={(val) => submit('customer.email',val)} />
<LineEditor bind:value={doc.customer.email} editable={editable} onSet={(val) => update('customer.email',val)} />
</td>
</tr>
</tbody>
</table>
</fieldset>
<fieldset class="sender">
<legend>{t('document.sender')}</legend>
<legend>{t('sender')}</legend>
<table>
<tbody>
<tr>
<td colspan="2">
<MultilineEditor bind:value={doc.sender.name} editable={editable} onSet={(val) => submit('sender.name',val)} />
<MultilineEditor bind:value={doc.sender.name} editable={editable} onSet={(val) => update('sender.name',val)} />
</td>
</tr>
<tr>
<th>{t('document.court')}:</th>
<th>{t('local_court')}:</th>
<td>
<LineEditor bind:value={doc.sender.court} editable={editable} onSet={(val) => submit('sender.court',val)} />
<LineEditor bind:value={doc.sender.court} editable={editable} onSet={(val) => update('sender.court',val)} />
</td>
</tr>
<tr>
<th>{t('document.tax_id')}:</th>
<th>{t('tax_id')}:</th>
<td>
<LineEditor bind:value={doc.sender.tax_id} editable={editable} onSet={(val) => submit('sender.tax_id',val)} />
<LineEditor bind:value={doc.sender.tax_id} editable={editable} onSet={(val) => update('sender.tax_id',val)} />
</td>
</tr>
<tr>
<th>{t('document.bank_account')}:</th>
<th>{t('bank_account')}:</th>
<td>
<MultilineEditor bind:value={doc.sender.bank_account} editable={editable} onSet={(val) => submit('sender.bank_account',val)} />
<MultilineEditor bind:value={doc.sender.bank_account} editable={editable} onSet={(val) => update('sender.bank_account',val)} />
</td>
</tr>
</tbody>
</table>
</fieldset>
<fieldset class="invoice_data">
<legend>{t('document.type_'+doc.type)}</legend>
<legend>{t('type_'+doc.type)}</legend>
<table>
<tbody>
<tr>
<th>{t('document.number')}:</th>
<td><LineEditor bind:value={doc.number} editable={editable} onSet={(val) => submit('number',val)} /></td>
<th>{t('number')}:</th>
<td><LineEditor bind:value={doc.number} editable={editable} onSet={(val) => update('number',val)} /></td>
</tr>
<tr>
<th>{t('document.state')}:</th>
<StateSelector selected={doc.state} onchange={changeState} onSet={(val) => submit('state',val)} />
<th>{t('state')}:</th>
<StateSelector selected={doc.state} onchange={changeState} onSet={(val) => update('state',val)} />
</tr>
<tr>
<th>{t('document.date')}:</th>
<LineEditor bind:value={doc.date} editable={editable} onSet={(val) => submit('date',val)} />
<th>{t('date')}:</th>
<LineEditor bind:value={doc.date} editable={editable} onSet={(val) => update('date',val)} />
</tr>
<tr>
<th>{t('document.delivery')}:</th>
<LineEditor bind:value={doc.delivery} editable={editable} onSet={(val) => submit('delivery',val)} />
<th>{t('delivery_date')}:</th>
<LineEditor bind:value={doc.delivery} editable={editable} onSet={(val) => update('delivery',val)} />
</tr>
<tr>
<th>{t('document.template')}:</th>
<th>{t('template')}:</th>
<td>
{#if editable}
<TemplateSelector company={doc.company.id} bind:value={doc.template.id} onchange={() => submit('template_id',doc.template.id)} />
<TemplateSelector company={doc.company.id} bind:value={doc.template.id} onchange={() => update('template_id',doc.template.id)} />
{:else}
{doc.template.name}
{/if}
@@ -186,30 +206,30 @@
</table>
</fieldset>
<fieldset class="clear">
<legend>{t('document.head')}</legend>
<MarkdownEditor bind:value={doc.head} editable={editable} onSet={(val) => submit('head',val)} />
<legend>{t('head')}</legend>
<MarkdownEditor bind:value={doc.head} editable={editable} onSet={(val) => update('head',val)} />
</fieldset>
<fieldset>
<legend>
{t('document.positions')}
{t('positions')}
{#if editable}
<button onclick={() => position_select = true}>{t('document.add_position')}</button>
<button onclick={() => position_select = true}>{t('add_position')}</button>
{/if}
</legend>
<PositionList bind:document={doc} {submit} bind:error={error} />
<PositionList bind:document={doc} {update} bind:error={error} />
</fieldset>
<fieldset>
<legend>{t('document.footer')}</legend>
<MarkdownEditor bind:value={doc.footer} editable={editable} onSet={(val) => submit('footer',val)} />
<legend>{t('footer')}</legend>
<MarkdownEditor bind:value={doc.footer} editable={editable} onSet={(val) => update('footer',val)} />
</fieldset>
<fieldset>
<legend>{t('document.actions')}</legend>
<button onclick={render}>{t('document.create_pdf')}</button>
<legend>{t('actions')}</legend>
<button onclick={render} disabled={pdfDisabled}>{t('create_pdf')}</button>
<button onclick={() => router.navigate(`/document/${doc.id}/send`)} >{t('send_document')}</button>
</fieldset>
<fieldset>
<legend>TODO</legend>
<ul>
<li>Button zum Rendern des Dokuments einbauen</li>
<li>Button zum Versenden des Dokuments einbauen</li>
<li>Preise in den Company-Einstellungen ändern, wenn für eine Position der Preis geändert wird siehe <em>documents.db</em>, Tabelle <em>customer_prices</em></li>
<li>Preise in der Tabelle neu berechnen, wenn Positionen geändert werden</li>