implemented creation of successor document
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -12,7 +12,7 @@ public class Constants {
|
||||
|
||||
public static final Pattern POST_CODE = compile("(.*\\w+.*)\n(.*\\d+.*)\n(\\d{5}) (\\w+)",DOTALL);
|
||||
|
||||
|
||||
public static final String CLONE = "clone";
|
||||
public static final String CONFIG_DATABASE = "umbrella.modules.document.database";
|
||||
public static final String CONFIG_TEMPLATES = "umbrella.modules.document.templates";
|
||||
public static final String CONTACTS = "contacts";
|
||||
|
||||
@@ -459,6 +459,40 @@ public class DocumentApi extends BaseHandler implements DocumentService {
|
||||
return send(ex,db.save(doc).positions());
|
||||
}
|
||||
|
||||
private boolean postCloneDoc(long docId, HttpExchange ex, UmbrellaUser user) throws IOException {
|
||||
Type docType = null;
|
||||
try {
|
||||
docType = db.getType(Integer.parseInt(body(ex)));
|
||||
} catch (NumberFormatException nfe){
|
||||
throw UmbrellaException.invalidFieldException(BODY,"document type id");
|
||||
}
|
||||
|
||||
Document doc = getDocument(docId, user).a;
|
||||
|
||||
var companySettings = db.getCompanySettings(doc.companyId(),docType);
|
||||
var nextNumber = companySettings.nextDocId();
|
||||
|
||||
Document clone = new Document(
|
||||
0,
|
||||
doc.companyId(),
|
||||
nextNumber,
|
||||
docType,
|
||||
LocalDate.now(),
|
||||
NEW,
|
||||
doc.template(),
|
||||
doc.delivery(),
|
||||
doc.head(),
|
||||
doc.footer(),
|
||||
doc.currency(),
|
||||
doc.decimalSeparator(),
|
||||
doc.sender(),
|
||||
doc.customer(),
|
||||
new PositionList()
|
||||
);
|
||||
clone = db.save(clone);
|
||||
doc.positions().values().forEach(clone.positions()::add);
|
||||
return sendContent(ex,db.save(clone));
|
||||
}
|
||||
|
||||
private boolean postDocument(HttpExchange ex, UmbrellaUser user) throws IOException, UmbrellaException {
|
||||
var json = json(ex);
|
||||
@@ -522,6 +556,7 @@ public class DocumentApi extends BaseHandler implements DocumentService {
|
||||
private boolean postToDocument(HttpExchange ex, Path path, UmbrellaUser user, long docId) throws IOException, UmbrellaException {
|
||||
var head = path.pop();
|
||||
return switch (head){
|
||||
case CLONE -> postCloneDoc(docId,ex,user);
|
||||
case POSITION -> postDocumentPosition(docId,ex,user);
|
||||
case PATH_SEND -> sendDocument(ex,path,user,docId);
|
||||
case null, default -> super.doPost(path,ex);
|
||||
|
||||
@@ -469,6 +469,7 @@ CREATE TABLE IF NOT EXISTS {0} ( {1} VARCHAR(255) PRIMARY KEY, {2} VARCHAR(255)
|
||||
if (doc.positions().isDirty()) try {
|
||||
for (var entry : doc.positions().entrySet()){
|
||||
var pos = entry.getValue();
|
||||
if (pos.docId() != doc.id()) pos.setDocId(doc.id());
|
||||
if (pos.isNew()){
|
||||
insertInto(TABLE_POSITIONS,FIELD_DOCUMENT_ID,FIELD_POS, FIELD_ITEM_CODE,FIELD_AMOUNT, DESCRIPTION, TITLE,FIELD_UNIT,FIELD_PRICE,FIELD_TAX,FIELD_TIME_ID, OPTIONAL)
|
||||
.values(pos.docId(),pos.num(),pos.itemCode(),pos.amount(),pos.description(),pos.title(),pos.unit(),pos.unitPrice(),pos.tax(),pos.timeId(),pos.optional())
|
||||
|
||||
Reference in New Issue
Block a user