|
|
|
@ -13,14 +13,23 @@ import static de.srsoftware.tools.Optionals.isSet; |
|
|
|
import static de.srsoftware.tools.Strings.escapeHtmlEntities; |
|
|
|
import static de.srsoftware.tools.Strings.escapeHtmlEntities; |
|
|
|
import static de.srsoftware.umbrella.core.ConnectionProvider.connect; |
|
|
|
import static de.srsoftware.umbrella.core.ConnectionProvider.connect; |
|
|
|
import static de.srsoftware.umbrella.core.Constants.*; |
|
|
|
import static de.srsoftware.umbrella.core.Constants.*; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.FIELD_AMOUNT; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.FIELD_COMPANY; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.FIELD_CUSTOMER; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.FIELD_DOCUMENT; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.FIELD_ITEM_CODE; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.FIELD_PRICE_FORMAT; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.FIELD_TIME_ID; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.FIELD_TYPE; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.Constants.FIELD_UNIT; |
|
|
|
import static de.srsoftware.umbrella.core.Paths.LIST; |
|
|
|
import static de.srsoftware.umbrella.core.Paths.LIST; |
|
|
|
import static de.srsoftware.umbrella.core.Paths.STATES; |
|
|
|
import static de.srsoftware.umbrella.core.Paths.STATES; |
|
|
|
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE; |
|
|
|
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_UNPROCESSABLE; |
|
|
|
import static de.srsoftware.umbrella.core.Util.request; |
|
|
|
import static de.srsoftware.umbrella.core.Util.request; |
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*; |
|
|
|
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.*; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.model.Document.State.NEW; |
|
|
|
|
|
|
|
import static de.srsoftware.umbrella.core.model.Document.State.SENT; |
|
|
|
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.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.*; |
|
|
|
@ -46,8 +55,8 @@ import de.srsoftware.umbrella.core.ModuleRegistry; |
|
|
|
import de.srsoftware.umbrella.core.api.*; |
|
|
|
import de.srsoftware.umbrella.core.api.*; |
|
|
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; |
|
|
|
import de.srsoftware.umbrella.core.exceptions.UmbrellaException; |
|
|
|
import de.srsoftware.umbrella.core.model.*; |
|
|
|
import de.srsoftware.umbrella.core.model.*; |
|
|
|
|
|
|
|
import de.srsoftware.umbrella.core.model.Customer; |
|
|
|
import de.srsoftware.umbrella.documents.model.*; |
|
|
|
import de.srsoftware.umbrella.documents.model.*; |
|
|
|
import de.srsoftware.umbrella.documents.model.Customer; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.text.MessageFormat; |
|
|
|
import java.text.MessageFormat; |
|
|
|
@ -400,6 +409,11 @@ public class DocumentApi extends BaseHandler implements DocumentService { |
|
|
|
return new JSONArray(s); |
|
|
|
return new JSONArray(s); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Map<Long, Document> list(long companyId) throws UmbrellaException{ |
|
|
|
|
|
|
|
return db.listDocs(companyId); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean listCompaniesDocuments(HttpExchange ex, UmbrellaUser user, Token token) throws UmbrellaException { |
|
|
|
private boolean listCompaniesDocuments(HttpExchange ex, UmbrellaUser user, Token token) throws UmbrellaException { |
|
|
|
try { |
|
|
|
try { |
|
|
|
var json = json(ex); |
|
|
|
var json = json(ex); |
|
|
|
@ -407,7 +421,7 @@ public class DocumentApi extends BaseHandler implements DocumentService { |
|
|
|
long companyId = json.getLong(COMPANY); |
|
|
|
long companyId = json.getLong(COMPANY); |
|
|
|
var company = modules.companyService().get(companyId); |
|
|
|
var company = modules.companyService().get(companyId); |
|
|
|
if (!modules.companyService().membership(companyId,user.id())) throw forbidden("You are mot a member of company {0}",company); |
|
|
|
if (!modules.companyService().membership(companyId,user.id())) throw forbidden("You are mot a member of company {0}",company); |
|
|
|
var docs = db.listDocs(companyId); |
|
|
|
var docs = list(companyId); |
|
|
|
var map = new HashMap<Long,Object>(); |
|
|
|
var map = new HashMap<Long,Object>(); |
|
|
|
for (var entry : docs.entrySet()) map.put(entry.getKey(),entry.getValue().summary()); |
|
|
|
for (var entry : docs.entrySet()) map.put(entry.getKey(),entry.getValue().summary()); |
|
|
|
return sendContent(ex,new JSONObject(map).toString(2)); |
|
|
|
return sendContent(ex,new JSONObject(map).toString(2)); |
|
|
|
@ -417,6 +431,7 @@ public class DocumentApi extends BaseHandler implements DocumentService { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean patchDocument(long docId, UmbrellaUser user, HttpExchange ex) throws UmbrellaException, IOException { |
|
|
|
private boolean patchDocument(long docId, UmbrellaUser user, HttpExchange ex) throws UmbrellaException, IOException { |
|
|
|
var doc = getDocument(docId,user).a; |
|
|
|
var doc = getDocument(docId,user).a; |
|
|
|
doc.patch(json(ex)); |
|
|
|
doc.patch(json(ex)); |
|
|
|
|