refactored translations, preparing sending of document
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user