implemented state update after sending document, returning to document list
This commit is contained in:
@@ -7,6 +7,7 @@ import static de.srsoftware.umbrella.core.Constants.LANGUAGE;
|
|||||||
import static de.srsoftware.umbrella.core.Constants.NAME;
|
import static de.srsoftware.umbrella.core.Constants.NAME;
|
||||||
import static de.srsoftware.umbrella.core.Constants.THEME;
|
import static de.srsoftware.umbrella.core.Constants.THEME;
|
||||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||||
|
import static java.text.MessageFormat.format;
|
||||||
|
|
||||||
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@@ -46,7 +47,10 @@ public class User {
|
|||||||
return new UmbrellaUser(id.longValue(), name, addr, theme, lang);
|
return new UmbrellaUser(id.longValue(), name, addr, theme, lang);
|
||||||
}
|
}
|
||||||
return new User(name,addr,lang);
|
return new User(name,addr,lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return format("{0} ({1})",name,email);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.forbidden
|
|||||||
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.missingFieldException;
|
||||||
import static de.srsoftware.umbrella.documents.Constants.*;
|
import static de.srsoftware.umbrella.documents.Constants.*;
|
||||||
import static de.srsoftware.umbrella.documents.model.Document.State.NEW;
|
import static de.srsoftware.umbrella.documents.model.Document.State.NEW;
|
||||||
|
import static de.srsoftware.umbrella.documents.model.Document.State.SENT;
|
||||||
import static java.lang.System.Logger.Level.DEBUG;
|
import static java.lang.System.Logger.Level.DEBUG;
|
||||||
import static java.lang.System.Logger.Level.WARNING;
|
import static java.lang.System.Logger.Level.WARNING;
|
||||||
import static java.net.HttpURLConnection.*;
|
import static java.net.HttpURLConnection.*;
|
||||||
@@ -218,20 +219,19 @@ public class DocumentApi extends BaseHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean sendDocument(HttpExchange ex, Path path, UmbrellaUser user, long docId) throws IOException, UmbrellaException {
|
private boolean sendDocument(HttpExchange ex, Path path, UmbrellaUser user, long docId) throws IOException, UmbrellaException {
|
||||||
var doc = getDocument(docId,user).a;
|
var doc = getDocumentWithCompanyData(docId,user);
|
||||||
var rendered = renderDocument(doc,user);
|
var rendered = renderDocument(doc,user);
|
||||||
var json = json(ex);
|
var json = json(ex);
|
||||||
if (!(json.has(EMAIL) && json.get(EMAIL) instanceof String email)) throw missingFieldException(EMAIL);
|
if (!(json.has(EMAIL) && json.get(EMAIL) instanceof String email)) throw missingFieldException(EMAIL);
|
||||||
if (!(json.has(SUBJECT) && json.get(SUBJECT) instanceof String subject)) throw missingFieldException(SUBJECT);
|
if (!(json.has(SUBJECT) && json.get(SUBJECT) instanceof String subject)) throw missingFieldException(SUBJECT);
|
||||||
if (!(json.has(CONTENT) && json.get(CONTENT) instanceof String content)) throw missingFieldException(CONTENT);
|
if (!(json.has(CONTENT) && json.get(CONTENT) instanceof String content)) throw missingFieldException(CONTENT);
|
||||||
|
LOG.log(WARNING,"Updating settings of company-customer-document combination not implemented!");
|
||||||
var attachment = new Attachment(doc.number()+".pdf",rendered.mimeType(),rendered.bytes());
|
var attachment = new Attachment(doc.number()+".pdf",rendered.mimeType(),rendered.bytes());
|
||||||
var message = new Message(user,subject,content,null,List.of(attachment));
|
var message = new Message(user,subject,content,null,List.of(attachment));
|
||||||
var envelope = new Envelope(message,new User(doc.customer().name(),new EmailAddress(email),doc.customer().language()));
|
var envelope = new Envelope(message,new User(doc.customer().shortName(),new EmailAddress(email),doc.customer().language()));
|
||||||
messages.send(envelope);
|
messages.send(envelope);
|
||||||
// TODO postBox.send(…)
|
db.save(doc.set(SENT));
|
||||||
|
return ok(ex);
|
||||||
return sendEmptyResponse(HTTP_NOT_IMPLEMENTED,ex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean getCompanies(HttpExchange ex, UmbrellaUser user, Token token) throws IOException, UmbrellaException {
|
private boolean getCompanies(HttpExchange ex, UmbrellaUser user, Token token) throws IOException, UmbrellaException {
|
||||||
|
|||||||
@@ -91,6 +91,13 @@ public final class Customer implements Mappable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String shortName(){
|
||||||
|
var lines = name.split("\n");
|
||||||
|
var result = lines[0];
|
||||||
|
if (lines.length>1 && !lines[1].matches(".*\\d.*")) result += " "+lines[1];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public String taxNumber() {
|
public String taxNumber() {
|
||||||
return taxNumber;
|
return taxNumber;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,14 @@ package de.srsoftware.umbrella.documents.model;
|
|||||||
import static de.srsoftware.umbrella.core.Constants.*;
|
import static de.srsoftware.umbrella.core.Constants.*;
|
||||||
import static de.srsoftware.umbrella.core.Util.markdown;
|
import static de.srsoftware.umbrella.core.Util.markdown;
|
||||||
import static de.srsoftware.umbrella.documents.Constants.*;
|
import static de.srsoftware.umbrella.documents.Constants.*;
|
||||||
|
import static java.lang.System.Logger.Level.WARNING;
|
||||||
|
|
||||||
import de.srsoftware.tools.Mappable;
|
import de.srsoftware.tools.Mappable;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
public final class Position implements Mappable {
|
public final class Position implements Mappable {
|
||||||
|
public static final System.Logger LOG = System.getLogger(Position.class.getSimpleName());
|
||||||
private long docId;
|
private long docId;
|
||||||
private final int num;
|
private final int num;
|
||||||
private String itemCode;
|
private String itemCode;
|
||||||
@@ -121,7 +122,9 @@ public final class Position implements Mappable {
|
|||||||
case FIELD_TAX: tax = json.getInt(key); break;
|
case FIELD_TAX: tax = json.getInt(key); break;
|
||||||
case TITLE: title = json.getString(key); break;
|
case TITLE: title = json.getString(key); break;
|
||||||
case FIELD_UNIT: unit = json.getString(key); break;
|
case FIELD_UNIT: unit = json.getString(key); break;
|
||||||
case FIELD_UNIT_PRICE: unitPrice = json.getLong(key); break;
|
case FIELD_UNIT_PRICE: unitPrice = json.getLong(key);
|
||||||
|
LOG.log(WARNING,"Updating unit price for customer in company settings not implemented!");
|
||||||
|
break;
|
||||||
default: key = null;
|
default: key = null;
|
||||||
}
|
}
|
||||||
if (key != null) dirtyFields.add(key);
|
if (key != null) dirtyFields.add(key);
|
||||||
|
|||||||
@@ -4,11 +4,14 @@
|
|||||||
import { t } from '../../translations.svelte.js';
|
import { t } from '../../translations.svelte.js';
|
||||||
import TypeSelector from './TypeSelector.svelte';
|
import TypeSelector from './TypeSelector.svelte';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let error = null;
|
let error = null;
|
||||||
let companies = {};
|
let companies = {};
|
||||||
let documents = null;
|
let documents = null;
|
||||||
let selected_company = null;
|
let selected_company = null;
|
||||||
let router = useTinyRouter();
|
let router = useTinyRouter();
|
||||||
|
let company_id = +router.query.company_id;
|
||||||
let docType = 0;
|
let docType = 0;
|
||||||
|
|
||||||
async function loadCompanies(){
|
async function loadCompanies(){
|
||||||
@@ -19,9 +22,20 @@
|
|||||||
} else {
|
} else {
|
||||||
error = await resp.text();
|
error = await resp.text();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (company_id) {
|
||||||
|
for (var comp of companies){
|
||||||
|
if (comp.id == company_id){
|
||||||
|
load(comp);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function load(company){
|
async function load(company){
|
||||||
|
router.navigate(`/document?company_id=${company.id}`);
|
||||||
selected_company = company;
|
selected_company = company;
|
||||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/list`;
|
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/list`;
|
||||||
const resp = await fetch(url,{
|
const resp = await fetch(url,{
|
||||||
|
|||||||
@@ -37,13 +37,13 @@
|
|||||||
async function doSend(){
|
async function doSend(){
|
||||||
var data = {email:email,subject:subject,content:content};
|
var data = {email:email,subject:subject,content:content};
|
||||||
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${id}/send`;
|
const url = `${location.protocol}//${location.host.replace('5173','8080')}/api/document/${id}/send`;
|
||||||
const resp = fetch(url,{
|
const resp = await fetch(url,{
|
||||||
credentials:'include',
|
credentials:'include',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(data)
|
body: JSON.stringify(data)
|
||||||
});
|
});
|
||||||
if (resp.ok){
|
if (resp.ok){
|
||||||
router.navigate('/document');
|
router.navigate(`/document?company_id=${doc.company.id}`);
|
||||||
} else {
|
} else {
|
||||||
error = await resp.text();
|
error = await resp.text();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ public class Constants {
|
|||||||
public static final String CONFIG_SMTP_PORT = "umbrella.modules.message.smtp.port";
|
public static final String CONFIG_SMTP_PORT = "umbrella.modules.message.smtp.port";
|
||||||
public static final String CONFIG_SMTP_USER = "umbrella.modules.message.smtp.user";
|
public static final String CONFIG_SMTP_USER = "umbrella.modules.message.smtp.user";
|
||||||
|
|
||||||
public static final String DEBUG_ADDREESS = "debug_addres";
|
public static final String DEBUG_ADDREESS = "umbrella.modules.message.debug_address";
|
||||||
public static final String ENVELOPE_FROM = "mail.smtp.from";
|
public static final String ENVELOPE_FROM = "mail.smtp.from";
|
||||||
public static final String FIELD_MESSAGES = "messages";
|
public static final String FIELD_MESSAGES = "messages";
|
||||||
public static final String FIELD_HOST = "host";
|
public static final String FIELD_HOST = "host";
|
||||||
|
|||||||
@@ -62,7 +62,9 @@ public class Translations extends PathHandler implements Translator {
|
|||||||
} else current = null;
|
} else current = null;
|
||||||
}
|
}
|
||||||
var translated = current instanceof String translation ? translation : text;
|
var translated = current instanceof String translation ? translation : text;
|
||||||
for (var entry : fills.entrySet()) translated = translated.replaceAll("\\{"+entry.getKey()+"}",entry.getValue());
|
if (fills != null) for (var entry : fills.entrySet()) {
|
||||||
|
translated = translated.replaceAll("\\{"+entry.getKey()+"}",entry.getValue());
|
||||||
|
}
|
||||||
return translated;
|
return translated;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return text;
|
return text;
|
||||||
|
|||||||
Reference in New Issue
Block a user