use of eu.ggnet.dwoss.redtape.ee.entity.Dossier in project dwoss by gg-net.
the class RedTapeWorkflow method validate.
protected void validate(Document altered, Document previous) {
// Check that the in db is correct
Dossier dos = previous.getDossier();
if (altered.getOptLock() != previous.getOptLock())
throw new IllegalStateException("The Previous Document has a different optLock, so it was changed since the last read. Please try cancel, refresh the dossier and that the change.");
if (previous.getConditions().contains(Document.Condition.CANCELED))
throw new IllegalStateException("The Previous Document is canceled.\nAltered: " + altered + "\nPrevious: " + previous);
for (DocumentType type : DocumentType.values()) {
if (type == DocumentType.CREDIT_MEMO || type == DocumentType.COMPLAINT || type == DocumentType.ANNULATION_INVOICE)
continue;
if (dos.getActiveDocuments(type).size() > 1)
throw new IllegalStateException("The Dossier(id=" + dos.getId() + ") has more than one active Document of Type " + type + "\n" + dos + "\n" + dos.getActiveDocuments(type));
}
if (!previous.isActive())
throw new IllegalStateException("The Previous Document is not active.\nAltered: " + altered + "\nPrevious: " + previous);
// TODO: Check, that the Type Change is allowed (e.g. from RETURNS to CAPITAL_ASSET obviously not
if (altered.getType() != previous.getType())
return;
if (!previous.isClosed())
return;
// A Complaint is the only Document, that may be reported twice, so a reopening is possible.
if (previous.getType() == DocumentType.COMPLAINT)
return;
// Now to the restrictive handling of closed documents.
if (!dos.changesAllowed(altered.getDossier()))
throw new IllegalStateException("The Dossier is clossed and supplied changes are not allowed." + "\nAltered: " + altered.getDossier() + "\nPrevious: " + dos);
DocumentEquals documentEquals = new DocumentEquals().ignore(ID, ACTIVE, HISTORY, PREDECESSOR, DIRECTIVE, CONDITIONS, FLAGS, SETTLEMENTS).ignoreAddresses().igonrePositionOrder().ignorePositions(PositionType.COMMENT);
if (!documentEquals.equals(previous, altered))
throw new IllegalStateException("The Document is clossed and supplied changes are not allowed." + documentEquals.equalsMessage(previous, altered));
}
use of eu.ggnet.dwoss.redtape.ee.entity.Dossier in project dwoss by gg-net.
the class DocumentRendererTryout method main.
public static void main(String[] args) {
DocumentSupporterOperation documentSupporter = new DocumentSupporterOperation();
documentSupporter.setMandator(Sample.MANDATOR);
Dossier dos = new Dossier();
dos.setPaymentMethod(PaymentMethod.ADVANCE_PAYMENT);
dos.setDispatch(true);
dos.setCustomerId(1);
Document doc = new Document();
doc.setTaxType(TaxType.GENERAL_SALES_TAX_DE_SINCE_2007);
doc.setType(DocumentType.ORDER);
doc.setActive(true);
doc.setDirective(Document.Directive.WAIT_FOR_MONEY);
doc.setHistory(new DocumentHistory("JUnit", "Automatische Erstellung eines leeren Dokuments"));
Address a = new Address("Herr Muh\nMuhstrasse 7\n12345 Muhstadt");
doc.setInvoiceAddress(a);
doc.setShippingAddress(a);
dos.add(doc);
NaivBuilderUtil.overwriteTax(doc.getTaxType());
doc.append(NaivBuilderUtil.comment());
doc.append(NaivBuilderUtil.service());
doc.append(NaivBuilderUtil.shippingcost());
System.out.println("Tax: " + doc.getSingleTax());
System.out.println("Netto " + doc.getPrice());
System.out.println("Brutto: " + doc.toAfterTaxPrice());
System.out.println("SumTax: " + (doc.toAfterTaxPrice() - doc.getPrice()));
JasperPrint print = documentSupporter.render(doc, DocumentViewType.DEFAULT);
JRViewer viewer = new JRViewer(print);
JFrame frame = new JFrame("Viewer");
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(viewer, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
Aggregations