Search in sources :

Example 1 with Dossier

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());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) LogicTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) DossierEmo(eu.ggnet.dwoss.redtape.ee.emo.DossierEmo) StockTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.StockTransactionEmo) StockTransaction(eu.ggnet.dwoss.stock.ee.entity.StockTransaction)

Example 2 with Dossier

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;
}
Also used : StockTransactionPosition(eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao) Document(eu.ggnet.dwoss.redtape.ee.entity.Document)

Example 3 with Dossier

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;
}
Also used : Tuple2(eu.ggnet.dwoss.util.Tuple2) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao)

Example 4 with Dossier

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} &amp; ( {@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;
}
Also used : Condition(eu.ggnet.dwoss.redtape.ee.entity.Document.Condition) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao)

Example 5 with Dossier

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);
}
Also used : Dossier(eu.ggnet.dwoss.redtape.ee.entity.Dossier) Document(eu.ggnet.dwoss.redtape.ee.entity.Document)

Aggregations

Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)47 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)30 Test (org.junit.Test)17 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)11 DossierEao (eu.ggnet.dwoss.redtape.ee.eao.DossierEao)8 DocumentHistory (eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory)6 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)6 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)6 Address (eu.ggnet.dwoss.redtape.ee.entity.Address)5 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)4 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)3 AddressEmo (eu.ggnet.dwoss.redtape.ee.emo.AddressEmo)3 StockUnitEao (eu.ggnet.dwoss.stock.ee.eao.StockUnitEao)3 RepaymentCustomers (eu.ggnet.dwoss.mandator.api.value.RepaymentCustomers)2 PositionBuilder (eu.ggnet.dwoss.redtape.ee.entity.PositionBuilder)2 Reminder (eu.ggnet.dwoss.redtape.ee.entity.Reminder)2 RedTapeWorker (eu.ggnet.dwoss.redtapext.ee.RedTapeWorker)2 ReportLineEao (eu.ggnet.dwoss.report.ee.eao.ReportLineEao)2 Report (eu.ggnet.dwoss.report.ee.entity.Report)2 eu.ggnet.dwoss.rules (eu.ggnet.dwoss.rules)2