implemented state update after sending document, returning to document list
This commit is contained in:
@@ -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.documents.Constants.*;
|
||||
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.WARNING;
|
||||
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 {
|
||||
var doc = getDocument(docId,user).a;
|
||||
var doc = getDocumentWithCompanyData(docId,user);
|
||||
var rendered = renderDocument(doc,user);
|
||||
var json = json(ex);
|
||||
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(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 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);
|
||||
// TODO postBox.send(…)
|
||||
|
||||
return sendEmptyResponse(HTTP_NOT_IMPLEMENTED,ex);
|
||||
db.save(doc.set(SENT));
|
||||
return ok(ex);
|
||||
}
|
||||
|
||||
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() {
|
||||
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.Util.markdown;
|
||||
import static de.srsoftware.umbrella.documents.Constants.*;
|
||||
import static java.lang.System.Logger.Level.WARNING;
|
||||
|
||||
import de.srsoftware.tools.Mappable;
|
||||
import java.util.*;
|
||||
import org.json.JSONObject;
|
||||
|
||||
public final class Position implements Mappable {
|
||||
|
||||
public static final System.Logger LOG = System.getLogger(Position.class.getSimpleName());
|
||||
private long docId;
|
||||
private final int num;
|
||||
private String itemCode;
|
||||
@@ -121,7 +122,9 @@ public final class Position implements Mappable {
|
||||
case FIELD_TAX: tax = json.getInt(key); break;
|
||||
case TITLE: title = 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;
|
||||
}
|
||||
if (key != null) dirtyFields.add(key);
|
||||
|
||||
Reference in New Issue
Block a user