Search in sources :

Example 6 with DossierEao

use of eu.ggnet.dwoss.redtape.ee.eao.DossierEao in project dwoss by gg-net.

the class UnitProcessorOperation method findEditableUnit.

/**
 * Returns a editable UniqueUnit.
 * An Exception is thrown if:
 * <ul>
 * <li>No UniqueUnit with refurbishedId</li>
 * <li>No StockUnit for UniqueUnit</li>
 * <li>StockUnit is on Transaction</li>
 * <li>No SopoUnit with refurbishedId</li>
 * <li>No SopoUnit UniqueUnit miss match</li>
 * </ul>
 * The Operation is discovert via:
 * <ul>
 * <li>If on an AlphaAcount, and operation is allowed, returns appropriated operation</li>
 * <li>If on no Auftrag, returns Sales</li>
 * <li>If on any other Auftrag, returns null</li>
 * </ul>
 *
 * @param refurbishedIdOrSerial the refurbishedId or the serial, both are tried
 * @return a EditableUnit with, the editable UniqueUnit, the refrencing StockUnit, the Operation it is in, and the PartNo
 * @throws UserInfoException if refurbishedId is not ok.
 */
@Override
public EditableUnit findEditableUnit(String refurbishedIdOrSerial) throws UserInfoException {
    if (StringUtils.isBlank(refurbishedIdOrSerial))
        throw new UserInfoException("Keine SopoNr/Seriennummer eingegeben");
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    UniqueUnit uniqueUnit = uniqueUnitEao.findByIdentifier(REFURBISHED_ID, refurbishedIdOrSerial);
    if (uniqueUnit == null)
        uniqueUnit = uniqueUnitEao.findByIdentifier(SERIAL, refurbishedIdOrSerial);
    if (uniqueUnit == null)
        throw new UserInfoException("Keine Gerät mit SopoNr/Seriennummer " + refurbishedIdOrSerial + " gefunden");
    StockUnit stockUnit;
    ReceiptOperation operation = ReceiptOperation.SALEABLE;
    stockUnit = new StockUnitEao(stockEm).findByUniqueUnitId(uniqueUnit.getId());
    if (stockUnit == null)
        throw new UserInfoException("Keine Lagergerät für SopoNr " + uniqueUnit.getIdentifier(REFURBISHED_ID) + " gefunden, bearbeitung unzulässig");
    LogicTransaction lt = new LogicTransactionEao(stockEm).findByUniqueUnitId(uniqueUnit.getId());
    if (lt != null) {
        operation = receiptCustomers.getOperation(new DossierEao(redTapeEm).findById(lt.getDossierId()).getCustomerId()).orElse(ReceiptOperation.IN_SALE);
    }
    // Lazyinit
    uniqueUnit.fetchEager();
    return new EditableUnit(uniqueUnit, stockUnit, operation, uniqueUnit.getProduct() == null ? "" : uniqueUnit.getProduct().getPartNo());
}
Also used : UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) StockUnitEao(eu.ggnet.dwoss.stock.ee.eao.StockUnitEao) LogicTransaction(eu.ggnet.dwoss.stock.ee.entity.LogicTransaction) DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) LogicTransactionEao(eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao) StockUnit(eu.ggnet.dwoss.stock.ee.entity.StockUnit) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)

Example 7 with DossierEao

use of eu.ggnet.dwoss.redtape.ee.eao.DossierEao 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 8 with DossierEao

use of eu.ggnet.dwoss.redtape.ee.eao.DossierEao 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 9 with DossierEao

use of eu.ggnet.dwoss.redtape.ee.eao.DossierEao in project dwoss by gg-net.

the class DocumentSupporterOperation method toXls.

@Override
public FileJacket toXls(String identifier) {
    DossierEao dossierEao = new DossierEao(redTapeEm);
    UniqueUnitEao uniqueUnitEao = new UniqueUnitEao(uuEm);
    List<Dossier> dossiers = dossierEao.findByIdentifier(identifier);
    if (dossiers.isEmpty())
        return null;
    Map<String, List<Object[]>> datas = new HashMap<>();
    for (Dossier dossier : dossiers) {
        for (Document document : dossier.getActiveDocuments()) {
            List<Object[]> rows = new ArrayList<>();
            datas.put(dossier.getIdentifier() + "_" + document.getType().getName() + "_" + (document.getIdentifier() == null ? "" : document.getIdentifier()), rows);
            for (Position pos : document.getPositions().values()) {
                if (pos.getUniqueUnitId() > 0) {
                    UniqueUnit uu = uniqueUnitEao.findById(pos.getUniqueUnitId());
                    rows.add(new Object[] { pos.getType().getName(), pos.getAmount(), pos.getName(), pos.getPrice(), pos.toAfterTaxPrice(), DateFormats.ISO.format(uu.getMfgDate()), uu.getProduct().getPrice(PriceType.MANUFACTURER_COST) });
                } else {
                    rows.add(new Object[] { pos.getType().getName(), pos.getAmount(), pos.getName(), pos.getPrice(), pos.toAfterTaxPrice(), null, null });
                }
            }
        }
    }
    STable template = new STable();
    CFormat euro = new CFormat(RIGHT, CURRENCY_EURO);
    CFormat date = new CFormat(CENTER, SHORT_DATE);
    CFormat percent = new CFormat(ITALIC, BLUE, null, null, null, PERCENT_FLOAT);
    template.setHeadlineFormat(new CFormat(BOLD_ITALIC, BLACK, WHITE, CENTER, new CBorder(BLACK)));
    template.add(new STableColumn("Type", 7)).add(new STableColumn("Menge", 10)).add(new STableColumn("Name", 30)).add(new STableColumn("Preis", 15, euro)).add(new STableColumn("Preis inc. Mwst", 15, euro)).add(new STableColumn("MfgDate", 13, date)).add(new STableColumn("CostPrice", 12, euro)).add(new STableColumn("%Cost", 12, percent).setAction(new SFormulaAction(SR(3), "/", SR(6))));
    CCalcDocument document = new TempCalcDocument();
    for (Map.Entry<String, List<Object[]>> entry : datas.entrySet()) {
        CSheet sheet = new CSheet(entry.getKey());
        STable table = new STable(template);
        table.setModel(new STableModelList(entry.getValue()));
        sheet.addBelow(table);
        document.add(sheet);
    }
    FileJacket fj = new FileJacket("Dossiers", ".xls", new JExcelLucidCalcWriter().write(document));
    return fj;
}
Also used : DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) JExcelLucidCalcWriter(eu.ggnet.lucidcalc.jexcel.JExcelLucidCalcWriter)

Example 10 with DossierEao

use of eu.ggnet.dwoss.redtape.ee.eao.DossierEao in project dwoss by gg-net.

the class DossierEmoIT method testRemoveHistory.

@Test
public void testRemoveHistory() throws Exception {
    DossierEmo dossierEmo = new DossierEmo(em);
    utx.begin();
    em.joinTransaction();
    Document last = dossierEmo.requestActiveDocumentBlock(2, "Addresse Zwei", "Comment", "Test");
    last.setActive(false);
    Dossier dossier = last.getDossier();
    for (int i = 0; i < 20; i++) {
        Document d = new Document(DocumentType.BLOCK, Document.Directive.NONE, new DocumentHistory("JUnit", "JUnit"));
        d.append(Position.builder().amount(1).type(PositionType.COMMENT).name("JUnit").description("JUnit").build());
        d.setActive(false);
        d.setInvoiceAddress(last.getInvoiceAddress());
        d.setShippingAddress(last.getShippingAddress());
        d.setPredecessor(last);
        dossier.add(d);
        em.persist(d);
        last = d;
    }
    last.setActive(true);
    utx.commit();
    utx.begin();
    em.joinTransaction();
    dossier = new DossierEao(em).findById(dossier.getId());
    assertTrue(dossier.getDocuments().size() > 10);
    dossierEmo.removeHistoryFromBlock(dossier.getId());
    utx.commit();
    utx.begin();
    em.joinTransaction();
    dossier = new DossierEao(em).findById(dossier.getId());
    assertEquals(1, dossier.getDocuments().size());
    utx.commit();
}
Also used : DossierEao(eu.ggnet.dwoss.redtape.ee.eao.DossierEao) DossierEmo(eu.ggnet.dwoss.redtape.ee.emo.DossierEmo) Test(org.junit.Test)

Aggregations

DossierEao (eu.ggnet.dwoss.redtape.ee.eao.DossierEao)14 Dossier (eu.ggnet.dwoss.redtape.ee.entity.Dossier)7 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)4 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)4 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)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 LogicTransaction (eu.ggnet.dwoss.stock.ee.entity.LogicTransaction)3 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)3 Test (org.junit.Test)3 DocumentHistory (eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory)2 LogicTransactionEao (eu.ggnet.dwoss.stock.ee.eao.LogicTransactionEao)2 UserInfoException (eu.ggnet.dwoss.util.UserInfoException)2 DossierEmo (eu.ggnet.dwoss.redtape.ee.emo.DossierEmo)1 Condition (eu.ggnet.dwoss.redtape.ee.entity.Document.Condition)1 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)1 CustomerDocument (eu.ggnet.dwoss.redtapext.ee.state.CustomerDocument)1 LogicTransactionEmo (eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo)1 StockTransactionPosition (eu.ggnet.dwoss.stock.ee.entity.StockTransactionPosition)1