|
|
|
|
@ -459,6 +459,40 @@ public class DocumentApi extends BaseHandler implements DocumentService {
@@ -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 {
@@ -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); |
|
|
|
|
|