refactored translations, preparing sending of document
This commit is contained in:
@@ -37,8 +37,8 @@ import de.srsoftware.document.zugferd.data.Currency;
|
||||
import de.srsoftware.tools.Pair;
|
||||
import de.srsoftware.tools.Path;
|
||||
import de.srsoftware.tools.SessionToken;
|
||||
import de.srsoftware.tools.Tuple;
|
||||
import de.srsoftware.umbrella.core.BaseHandler;
|
||||
import de.srsoftware.umbrella.core.Tuple;
|
||||
import de.srsoftware.umbrella.core.api.CompanyService;
|
||||
import de.srsoftware.umbrella.core.api.Translator;
|
||||
import de.srsoftware.umbrella.core.api.UserService;
|
||||
@@ -199,20 +199,25 @@ public class DocumentApi extends BaseHandler {
|
||||
case TEMPLATES -> postTemplateList(ex,user.get());
|
||||
case null -> postDocument(ex,user.get());
|
||||
default -> {
|
||||
var docId = 0L;
|
||||
try {
|
||||
docId = Long.parseLong(head);
|
||||
} catch (NumberFormatException ignored) {
|
||||
yield super.doPost(path,ex);
|
||||
}
|
||||
yield postToDocument(ex,path,user.get(),docId);
|
||||
var docId = Long.parseLong(head);
|
||||
yield switch (path.pop()){
|
||||
case null -> postToDocument(ex,path,user.get(),docId);
|
||||
case PATH_SEND -> sendDocument(ex,path,user.get(),docId);
|
||||
default -> super.doPost(path,ex);
|
||||
};
|
||||
}
|
||||
};
|
||||
} catch (NumberFormatException ignored) {
|
||||
return super.doPost(path,ex);
|
||||
} catch (UmbrellaException e) {
|
||||
return send(ex,e);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean sendDocument(HttpExchange ex, Path path, UmbrellaUser umbrellaUser, long docId) throws IOException {
|
||||
return sendEmptyResponse(HTTP_NOT_IMPLEMENTED,ex);
|
||||
}
|
||||
|
||||
private boolean getCompanies(HttpExchange ex, UmbrellaUser user, Token token) throws IOException, UmbrellaException {
|
||||
return sendContent(ex,companies.listCompaniesOf(user).stream().map(Company::toMap));
|
||||
}
|
||||
@@ -350,7 +355,7 @@ public class DocumentApi extends BaseHandler {
|
||||
.filter(filter)
|
||||
.findAny();
|
||||
if (optDoc.isEmpty()) throw UmbrellaException.notFound("Cannot render {0} {1}: Missing template \"{2}\"",type,document.number(),template);
|
||||
Function<String,String> translate = text -> translator.translate(user.language(),text);
|
||||
Function<String,String> translate = text -> translator.translate(user.language(),"document."+text.replaceAll(" ","_"));
|
||||
var pdfData = new HashMap<String,Object>();
|
||||
pdfData.put(FIELD_DOCUMENT,document.renderToMap());
|
||||
pdfData.put("translate",translate);
|
||||
|
||||
@@ -13,6 +13,7 @@ import de.srsoftware.configuration.JsonConfig;
|
||||
import de.srsoftware.document.api.*;
|
||||
import de.srsoftware.umbrella.core.model.UmbrellaUser;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -77,8 +78,11 @@ public abstract class TemplateDoc implements Document {
|
||||
}
|
||||
}
|
||||
tokens = findTokensIn(source);
|
||||
var opt = data.get("translate");
|
||||
@SuppressWarnings("unchecked")
|
||||
Function<String,String> translate = opt instanceof Function<?,?> fun ? (Function<String,String>) fun : s -> s;
|
||||
for (var token : tokens){
|
||||
var value = config.get("translations."+token).map(Object::toString).orElse(token).trim();
|
||||
var value = translate.apply(token);
|
||||
if (MIME_HTML.equals(mimeType())) value = value.replace("\n","<span class=\"break\"></span>\n");
|
||||
source = source.replace("<? "+token+" ?>",value);
|
||||
}
|
||||
|
||||
@@ -132,25 +132,25 @@
|
||||
<div class="sender data">
|
||||
<? document.sender.name ?><br/>
|
||||
<br/>
|
||||
<? Delivery date ?>: <? document.delivery ?>
|
||||
<? delivery date ?>: <? document.delivery ?>
|
||||
</div>
|
||||
</header>
|
||||
<h1><? document.type ?></h1>
|
||||
<h2>
|
||||
<span class="left"><? document.type ?> <? document.number ?></span>
|
||||
<span class="center"><? customer number ?>: <? document.customer.id ?></span>
|
||||
<span class="center"><? customer id ?>: <? document.customer.id ?></span>
|
||||
<span class="right"><? document.date ?></span>
|
||||
</h2>
|
||||
<hr/>
|
||||
<div class="head"><? document.head.rendered ?></div>
|
||||
<table>
|
||||
<tr>
|
||||
<th><? Position ?></th>
|
||||
<th><? Description ?></th>
|
||||
<th><? Price per unit ?></th>
|
||||
<th><? Amount ?></th>
|
||||
<th><? Price ?></th>
|
||||
<th><? Tax rate ?></th>
|
||||
<th><? position ?></th>
|
||||
<th><? description ?></th>
|
||||
<th><? price per unit ?></th>
|
||||
<th><? amount ?></th>
|
||||
<th><? price ?></th>
|
||||
<th><? tax rate ?></th>
|
||||
</tr>
|
||||
|
||||
<!-- positions -->
|
||||
@@ -171,7 +171,7 @@
|
||||
<!-- positions -->
|
||||
|
||||
<tr>
|
||||
<th class="right" colspan="5"><? Net sum ?>:</th>
|
||||
<th class="right" colspan="5"><? net sum ?>:</th>
|
||||
<th class="right"><? document.net_sum ?></th>
|
||||
</tr>
|
||||
|
||||
@@ -181,13 +181,13 @@
|
||||
<td></td>
|
||||
<td><? net_sum ?> + <? rate ?> =</td>
|
||||
<td><? gross_sum ?></td>
|
||||
<td colspan="2"><? contained tax: ?></td>
|
||||
<td colspan="2"><? contained tax ?>:</td>
|
||||
<td><? amount ?></td>
|
||||
</tr>
|
||||
|
||||
<!-- tax list -->
|
||||
<tr>
|
||||
<th class="right" colspan="5"><? Gross sum ?>:</th>
|
||||
<th class="right" colspan="5"><? gross sum ?>:</th>
|
||||
<th class="right"><? document.gross_sum ?></th>
|
||||
</tr>
|
||||
</table>
|
||||
@@ -196,12 +196,12 @@
|
||||
<tr>
|
||||
<td><? document.sender.name ?></td>
|
||||
<td>
|
||||
<? Tax id ?>: <? document.sender.tax_id ?><br/>
|
||||
<? tax id ?>: <? document.sender.tax_id ?><br/>
|
||||
<? local court ?>: <? document.sender.court ?><br/><br/>
|
||||
<div class="ad"><? document.type ?> <? created with ?> <a href="https://umbrella.srsoftware.de">Umbrella</a> <? by ?> <a href="https://srsoftware.de">SRSoftware</a></div>
|
||||
</td>
|
||||
<td>
|
||||
<? Bank account ?>:<br/>
|
||||
<? bank account ?>:<br/>
|
||||
<? document.sender.bank_account ?>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -216,7 +216,7 @@
|
||||
<div class="ad"><? document.type ?> <? created with ?> <a href="https://umbrella.srsoftware.de">Umbrella</a> <? by ?> <a href="https://srsoftware.de">SRSoftware</a></div>
|
||||
</div>
|
||||
<div class="bank_account">
|
||||
<? Bank account ?>:<br/>
|
||||
<? bank account ?>:<br/>
|
||||
<? document.sender.bank_account ?>
|
||||
</div>
|
||||
</div> -->
|
||||
|
||||
Reference in New Issue
Block a user