use of eu.ggnet.dwoss.redtape.ee.entity.Dossier in project dwoss by gg-net.
the class UnitDestroyerOperation method scrapDelete.
private void scrapDelete(final long targetCustomerId, final String operation, final UniqueUnit uniqueUnit, final String reason, final String arranger) {
UniqueUnit uu = new UniqueUnitEao(uuEm).findById(uniqueUnit.getId());
StockTransactionEmo stockTransactionEmo = new StockTransactionEmo(stockEm);
StockUnit stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uu.getId());
Document doc = new DossierEmo(redTapeEm).requestActiveDocumentBlock((int) targetCustomerId, "Blockaddresse KundenId " + targetCustomerId, "Erzeugung durch " + operation, arranger);
Dossier dos = doc.getDossier();
doc.append(Position.builder().type(PositionType.UNIT).amount(1).bookingAccount(postLedger.get(PositionType.UNIT, doc.getTaxType()).orElse(null)).description(UniqueUnitFormater.toDetailedDiscriptionLine(uu)).name(UniqueUnitFormater.toPositionName(uu)).uniqueUnitId(uu.getId()).uniqueUnitProductId(uu.getProduct().getId()).build());
doc.append(Position.builder().type(PositionType.COMMENT).amount(1).name(operation).description(reason + " by " + arranger).build());
LogicTransaction lt = new LogicTransactionEmo(stockEm).request(dos.getId());
// Implicit removes it from an existing LogicTransaction
lt.add(stockUnit);
StockTransaction st = stockTransactionEmo.requestDestroyPrepared(stockUnit.getStock().getId(), arranger, reason);
st.addUnit(stockUnit);
stockTransactionEmo.completeDestroy(arranger, Arrays.asList(st));
uu.addHistory(operation + " of Unit via " + st);
uu.setInternalComment(uu.getInternalComment() + ", " + operation + " of Unit.");
uu.setSalesChannel(UNKNOWN);
L.info("Executed Operation {} for uniqueUnit(id={},refurbishId={}), added to LogicTransaction({}) and Dossier({})", operation, uniqueUnit.getId(), uniqueUnit.getRefurbishId(), lt.getId(), dos.getIdentifier());
}
use of eu.ggnet.dwoss.redtape.ee.entity.Dossier in project dwoss by gg-net.
the class UnitProcessorOperation method cleanUpOldOperation.
private boolean cleanUpOldOperation(UniqueUnit uniqueUnit, StockUnit stockUnit, ReceiptOperation updateOperation, String operationComment, String arranger) {
LogicTransaction oldLogicTransaction = stockUnit.getLogicTransaction();
if (oldLogicTransaction != null) {
Dossier oldDossier = new DossierEao(redTapeEm).findById(oldLogicTransaction.getDossierId());
ReceiptOperation oldOperation = receiptCustomers.getOperation(oldDossier.getCustomerId()).orElse(null);
Document oldDocument = oldDossier.getActiveDocuments().get(0);
redTapeEm.flush();
redTapeEm.refresh(oldDocument, LockModeType.PESSIMISTIC_FORCE_INCREMENT);
if (!oldDocument.isActive())
throw new RuntimeException("The Document(id={}) has changed to inactive while locking, this was very unlikely, inform Administrator");
Position oldPosition = oldDocument.getPositionByUniqueUnitId(uniqueUnit.getId());
if (oldOperation == updateOperation) {
oldPosition.setDescription(oldPosition.getDescription() + ", Aufnahme: " + operationComment);
L.debug("old operation and update operation are {}, nothing more to do", updateOperation);
return false;
}
// cleanUp old Block and Auftrag
convertToComment(oldPosition, updateOperation);
L.debug("Old Operation cleanup, removed uniqueUnit(id={},refurbishId={}) from Dossier({})", new Object[] { uniqueUnit.getId(), uniqueUnit.getRefurbishId(), oldDossier.getIdentifier() });
}
if (updateOperation == ReceiptOperation.SALEABLE) {
if (oldLogicTransaction != null)
oldLogicTransaction.remove(stockUnit);
uniqueUnit.addHistory("Released for Sale by " + arranger);
L.debug("update operation is {}, nothing more to do", updateOperation);
return false;
}
return true;
}
use of eu.ggnet.dwoss.redtape.ee.entity.Dossier in project dwoss by gg-net.
the class UniversalSearcherOperation method searchDossiers.
/**
* Search for Dossiers where the search matches the identifier.
* This method will search for any partial matches from the beginning of a identifier if a wildcard is used.
* <p/>
* @param identifier the identifier to search for
* @return a List of Tuple2 containing dossier.id and string representation
*/
// Used in Misc. Unversal Search
@Override
public List<Tuple2<Long, String>> searchDossiers(String identifier) {
List<Tuple2<Long, String>> result = new ArrayList<>();
List<Dossier> dossiers = new DossierEao(redTapeEm).findByIdentifier(identifier);
for (Dossier dossier : dossiers) {
String s = DossierFormater.toHtmlSimple(dossier);
Tuple2<Long, String> tuple = new Tuple2<>(dossier.getId(), s);
result.add(tuple);
}
return result;
}
use of eu.ggnet.dwoss.redtape.ee.entity.Dossier in project dwoss by gg-net.
the class RedTapeCloserOperation method findReportable.
/**
* Discovers all Documents, which are in closing state.
* <p>
* Closing States are:
* <table border="1" >
* <thead>
* <tr><th>Case</th><th>Document Type</th><th>PaymentMethod</th><th>Conditions</th><th>Directive</th></tr>
* </thead>
* <tbody>
* <tr>
* <td>1</td>
* <td>{@link Type#ORDER}</td>
* <td>*</td>
* <td>{@link Condition#CANCELED}</td>
* <td>*</td>
* </tr>
* <tr>
* <td>2</td>
* <td>{@link Type#INVOICE} overwrites {@link Type#ORDER}</td>
* <td>{@link PaymentMethod#ADVANCE_PAYMENT}</td>
* <td>{@link Condition#PAID} & ( {@link Condition#SENT} | {@link Condition#PICKED_UP} )</td>
* <td>*</td>
* </tr>
* <tr>
* <td>3</td>
* <td>{@link Type#INVOICE} overwrites {@link Type#ORDER}</td>
* <td>{@link PaymentMethod#CASH_ON_DELIVERY}</td>
* <td>{@link Condition#SENT}</td>
* <td>*</td>
* </tr>
* <tr>
* <td>4</td>
* <td>{@link Type#INVOICE} overwrites {@link Type#ORDER}</td>
* <td>{@link PaymentMethod#DIRECT_DEBIT}</td>
* <td>{@link Condition#SENT} | {@link Condition#PICKED_UP}</td>
* <td>*</td>
* </tr>
* <tr>
* <td>5</td>
* <td>{@link Type#INVOICE} overwrites {@link Type#ORDER}</td>
* <td>{@link PaymentMethod#INVOICE}</td>
* <td>{@link Condition#SENT} | {@link Condition#PICKED_UP}</td>
* <td>*</td>
* </tr>
* <tr>
* <td>6</td>
* <td>{@link Type#ANNULATION_INVOICE} | {@link Type#CREDIT_MEMO}</td>
* <td>*</td>
* <td>*</td>
* <td>*</td>
* </tr>
* <tr>
* <td>7</td>
* <td>{@link Type#COMPLAINT}</td>
* <td>*</td>
* <td>*</td>
* <td>*</td>
* </tr>
* <tr>
* <td>8</td>
* <td>{@link Type#CAPITAL_ASSET} | {@link Type#RETURNS}</td>
* <td>*</td>
* <td>{@link Condition#PICKED_UP}</td>
* <td>{@link Directive#NONE}</td>
* </tr>
* </tbody>
* </table>
* Comments:
* <ul>
* <li>A canceled order will be closed, but not reported.</li>
* <li>A complaint is a very special case, which might be closed two times. See {@link RedTapeWorkflow#refreshAndPrepare(de.dw.redtape.entity.Document, de.dw.redtape.entity.Document)
* }</li>
* </ul>
* <p>
* @param monitor a optional monitor.
* @return all documents, which are in a closing state.
*/
private Set<Document> findReportable(IMonitor monitor) {
SubMonitor m = SubMonitor.convert(monitor);
m.start();
m.message(" lade offene Vorgänge");
List<Dossier> openDossiers = new DossierEao(redTapeEm).findByClosed(false);
m.worked(5);
m.setWorkRemaining(openDossiers.size());
Set<Document> closeable = new HashSet<>();
for (Dossier dossier : openDossiers) {
m.worked(1, " selecting " + dossier.getIdentifier());
// Check if there is only an order.
if (dossier.getActiveDocuments().size() == 1 && dossier.getActiveDocuments(DocumentType.ORDER).size() == 1) {
Document doc = dossier.getActiveDocuments(DocumentType.ORDER).get(0);
if (doc.getConditions().contains(CANCELED))
closeable.add(doc);
L.debug("Filtered not reportable {}, cause: canceled order", doc.getDossier().getIdentifier());
// Shortcut: If there is only an order, that is not canceled. we do not close it. If it is canceled, we close it.
continue;
}
// Check the Closing State. Every closable document is removed from the copied collection.
// If the collection is empty at the end, the dossier can be closed, meaning we remove all cases that we consider closing state.
List<Document> activeDocuments = new ArrayList<>(dossier.getActiveDocuments());
for (Iterator<Document> it = activeDocuments.iterator(); it.hasNext(); ) {
Document document = it.next();
Set<Condition> conditions = document.getConditions();
if (document.isClosed()) {
it.remove();
// At this point a ORDER is never the only Document, therfore we safly ignore it.
// All Repayments get reported on creation.
} else if (document.getType() == DocumentType.ORDER || document.getType() == DocumentType.ANNULATION_INVOICE || document.getType() == DocumentType.CREDIT_MEMO) {
it.remove();
} else if (document.getType() == DocumentType.INVOICE) {
switch(dossier.getPaymentMethod()) {
case ADVANCE_PAYMENT:
if (conditions.contains(PAID) && (conditions.contains(SENT) || conditions.contains(PICKED_UP)))
it.remove();
break;
case CASH_ON_DELIVERY:
if (conditions.contains(SENT))
it.remove();
break;
case DIRECT_DEBIT:
if (conditions.contains(SENT) || conditions.contains(PICKED_UP))
it.remove();
break;
case INVOICE:
if (conditions.contains(SENT) || conditions.contains(PICKED_UP))
it.remove();
break;
}
} else if (document.getType() == DocumentType.CAPITAL_ASSET || document.getType() == DocumentType.RETURNS) {
if (conditions.contains(PICKED_UP))
it.remove();
} else if (document.getType() == DocumentType.COMPLAINT) {
// A Complaint gets allways closed. See RedTapeWorkflow.refreshAndPrepare() for the reopening conditions.
it.remove();
}
// TODO: There might be a special case, that someone made the CreditMemo on the Invoice, but had a Complait before.
// We should cleanup this also. See: http://overload.ahrensburg.gg-net.de/jira/browse/DW-831
}
// Empty means, all documents in a dossier are either closed or in a closing state, expect Blocks and orders.
if (activeDocuments.isEmpty()) {
for (Document document : dossier.getActiveDocuments()) {
// The Order part is never Reported.
if (document.getType() == DocumentType.ORDER)
continue;
// Should never happen, no concept jet.
if (document.getType() == DocumentType.BLOCK)
continue;
// Don't close it twice
if (document.isClosed())
continue;
closeable.add(document);
}
} else if (L.isDebugEnabled()) {
List<String> shorts = new ArrayList<>();
String identifier = activeDocuments.get(0).getIdentifier();
for (Document document : activeDocuments) {
shorts.add(document.toTypeConditions());
}
L.debug("Filtered not reportable {}, cause: Not closeable documents: {}", identifier, shorts);
}
}
m.finish();
return closeable;
}
use of eu.ggnet.dwoss.redtape.ee.entity.Dossier in project dwoss by gg-net.
the class DocumentSupporterFlagIT method testClosed.
private void testClosed() {
Dossier dos = redTapeWorker.create(customerId, true, "JUnit");
Document doc = dos.getActiveDocuments().get(0);
addRandomPositions(doc);
doc = redTapeWorker.update(doc, null, arranger);
assertNotBriefed(doc);
dos = documentSupporter.briefed(doc, arranger);
assertExactlyBriefed(dos.getActiveDocuments().get(0));
doc = dos.getActiveDocuments().get(0);
doc.setClosed(true);
doc = redTapeWorker.update(doc, null, arranger);
assertExactlyBriefed(doc);
}
Aggregations