implemented creation of companies
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -21,8 +21,9 @@
|
||||
let { company } = $props();
|
||||
</script>
|
||||
|
||||
|
||||
<fieldset>
|
||||
{#if company}
|
||||
<legend>{t('edit_object',{object:company.name})}</legend>
|
||||
<fieldset>
|
||||
<legend>{t('name')}</legend>
|
||||
<LineEditor bind:value={company.name} editable={true} onSet={val => patch({name:val})} />
|
||||
@@ -31,5 +32,33 @@
|
||||
<legend>{t('address')}</legend>
|
||||
<Multiline bind:value={company.address} editable={true} onSet={val => patch({address:val})} />
|
||||
</fieldset>
|
||||
|
||||
{/if}
|
||||
<fieldset>
|
||||
<legend>{t('email')}</legend>
|
||||
<LineEditor bind:value={company.email} editable={true} onSet={val => patch({email:val})} />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>{t('phone')}</legend>
|
||||
<LineEditor bind:value={company.phone} editable={true} onSet={val => patch({phone:val})} />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>{t('bank_account')}</legend>
|
||||
<Multiline bind:value={company.bank_account} editable={true} onSet={val => patch({bank_account:val})} />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>{t('local_court')}</legend>
|
||||
<LineEditor bind:value={company.court} editable={true} onSet={val => patch({court:val})} />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>{t('tax_id')}</legend>
|
||||
<LineEditor bind:value={company.tax_number} editable={true} onSet={val => patch({tax_number:val})} />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>{t('last_customer_number')}</legend>
|
||||
<LineEditor bind:value={company.last_customer_number} editable={true} onSet={val => patch({last_customer_number:val})} />
|
||||
</fieldset>
|
||||
<fieldset>
|
||||
<legend>{t('customer_number_prefix')}</legend>
|
||||
<LineEditor bind:value={company.customer_number_prefix} editable={true} onSet={val => patch({customer_number_prefix:val})} />
|
||||
</fieldset>
|
||||
{/if}
|
||||
</fieldset>
|
||||
@@ -1,20 +1,38 @@
|
||||
<script>
|
||||
import {onMount} from 'svelte';
|
||||
import {api} from '../../urls.svelte.js';
|
||||
import {t} from '../../translations.svelte.js';
|
||||
import {onMount} from 'svelte';
|
||||
import {api} from '../../urls.svelte.js';
|
||||
import {t} from '../../translations.svelte.js';
|
||||
|
||||
import Editor from './Editor.svelte';
|
||||
import Editor from './Editor.svelte';
|
||||
import LineEditor from '../../Components/LineEditor.svelte';
|
||||
|
||||
let companies = $state(null);
|
||||
let error = $state(null);
|
||||
let selected = $state(0);
|
||||
let error = $state(null);
|
||||
let companies = $state(null);
|
||||
let new_company = $state({name:null,email:null});
|
||||
let selected = $state(0);
|
||||
let missing_fields = $derived(!new_company.name || !new_company.email?.includes('@'));
|
||||
|
||||
async function create_company(){
|
||||
const url = api('company');
|
||||
const resp = await fetch(url,{
|
||||
credentials : 'include',
|
||||
method : 'POST',
|
||||
body : JSON.stringify(new_company)
|
||||
});
|
||||
if (resp.ok){
|
||||
const company = await resp.json();
|
||||
companies[company.id] = company;
|
||||
error = null;
|
||||
} else {
|
||||
error = await resp.text();
|
||||
}
|
||||
}
|
||||
|
||||
async function loadCompanies(){
|
||||
const url = api('company/list');
|
||||
const resp = await fetch(url,{credentials:'include'});
|
||||
if (resp.ok){
|
||||
companies = await resp.json();
|
||||
console.log(companies);
|
||||
error = null;
|
||||
} else {
|
||||
error = await resp.text();
|
||||
@@ -29,7 +47,9 @@
|
||||
</script>
|
||||
|
||||
<fieldset>
|
||||
<legend>{t('companies')}</legend>
|
||||
<legend>
|
||||
{t('companies')}
|
||||
</legend>
|
||||
{#if error}
|
||||
<span class="error">{error}</span>
|
||||
{/if}
|
||||
@@ -49,6 +69,17 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="text" bind:value={new_company.name} />
|
||||
</td>
|
||||
<td>
|
||||
<input type="email" bind:value={new_company.email} />
|
||||
</td>
|
||||
<td>
|
||||
<button disabled={missing_fields} onclick={create_company}>{t('create_new_object',{object:t('company')})}</button>
|
||||
</td>
|
||||
</tr>
|
||||
{#each Object.entries(companies) as [cid, company]}
|
||||
<tr onclick={e => showDetail(cid)}>
|
||||
<td>{company.name}</td>
|
||||
|
||||
Reference in New Issue
Block a user