working on document list

This commit is contained in:
2025-07-09 00:27:06 +02:00
parent 58f69689e2
commit 5b5e6a9387
22 changed files with 1914 additions and 26 deletions

View File

@@ -2,28 +2,68 @@
import { onMount } from 'svelte';
import { t } from '../../translations.svelte.js';
let company = null;
let error = null;
let companies = {};
let documents = null;
let name = null;
async function loadCompanies(){
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/companies`;
var resp = await fetch(url,{ credentials: 'include'});
if (resp.ok){
companies = await resp.json();
console.log(companies);
} else {
error = await resp.text();
}
}
async function load(company){
name = company.name;
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/list`;
const resp = await fetch(url,{
credentials: 'include',
method: 'POST',
body: JSON.stringify({company:company.id})
});
if (resp.ok){
documents = await resp.json();
console.log(documents);
} else {
error = await resp.text();
}
}
onMount(loadCompanies);
</script>
<fieldset>
<legend>{t('documents.documents')}</legend>
<legend>{name ? t( 'document.list_of',name) : t('document.list')}</legend>
{#if error}
<div class="error">{error}</div>
{/if}
<div>
{t('documents.select_company')}
{t('document.select_company')}
{#each Object.entries(companies) as [id,company]}
<button onclick={() => load(company)}>{company.name}</button>
{/each}
</div>
{#if documents}
<table>
<thead>
</thead>
<tbody>
{#each Object.entries(documents) as [id,document]}
<tr>
<td>{id}</td>
<td>{document.number}</td>
<td>{document.date}</td>
<td>{document.customer.name.split('\n')[0]}</td>
<td>{document.sum/100 + document.currency}</td>
</tr>
{/each}
</tbody>
</table>
{/if}
</fieldset>