Search in sources :

Example 1 with DocumentEao

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

the class DocumentSupporterOperation method briefed.

/**
 * Sets the Flags {@link Flag#CUSTOMER_BRIEFED} and {@link Flag#CUSTOMER_EXACTLY_BRIEFED} at the document.
 * Also appends this change at the DocumentHistory.
 *
 * @param detached the document
 * @return the updated document
 */
@Override
public Dossier briefed(Document detached, String arranger) {
    L.info("Setting briefed at {}", DocumentFormater.toSimpleLine(detached));
    Document document = new DocumentEao(redTapeEm).findById(detached.getId());
    document.getDossier().fetchEager();
    document.add(Document.Flag.CUSTOMER_BRIEFED);
    document.add(Document.Flag.CUSTOMER_EXACTLY_BRIEFED);
    document.getHistory().setComment(document.getHistory().getComment() + ", Kunde wurde durch " + arranger + " informiert.");
    return document.getDossier();
}
Also used : DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao)

Example 2 with DocumentEao

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

the class RedTapeWorkerOperation method revertCreate.

/**
 * This method handles necessary cleanups if creation or update is canceled.
 * <p/>
 * If stock.LogicTransaction differs form Dossier.Document.Positions &rArr; change LogicTransaction.
 * <ul><li>Only LogicTransaction > Dossier.Document.Positions should be possible</li></ul>
 * If Dossier.isEmpty &rarr; delete.
 * If stock.LogicTransaction is empty &rarr; delete.
 */
@Override
public Document revertCreate(Document detached) throws UserInfoException {
    Document original = new DocumentEao(redTapeEm).findById(detached.getId());
    if (original.isActive() != detached.isActive())
        throw new UserInfoException("Das Document wurde durch jemand anderen inzwischen geändert, bitte neu laden.\n" + "Hint: original(" + original.getId() + ").active=" + original.isActive() + ", detached(" + detached.getId() + ").active=" + detached.isActive());
    if (original.getOptLock() != detached.getOptLock())
        throw new UserInfoException("Das Document wurde durch jemand anderen inzwischen geändert, bitte neu laden.\n" + "Hint: original(" + original.getId() + ").optLock=" + original.getOptLock() + ", detached(" + detached.getId() + ").optLock=" + detached.getOptLock());
    LogicTransactionEmo ltEmo = new LogicTransactionEmo(stockEm);
    if (!detached.isClosed())
        ltEmo.equilibrate(original.getDossier().getId(), original.getPositionsUniqueUnitIds());
    if (original.getDossier().getDocuments().size() == 1 && original.getPositions().isEmpty()) {
        redTapeEm.remove(original.getDossier());
        return null;
    }
    return original;
}
Also used : DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) LogicTransactionEmo(eu.ggnet.dwoss.stock.ee.emo.LogicTransactionEmo) UserInfoException(eu.ggnet.dwoss.util.UserInfoException) CustomerDocument(eu.ggnet.dwoss.redtapext.ee.state.CustomerDocument)

Example 3 with DocumentEao

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

the class CreditMemoReporterOperation method toOptimizedXls.

@Override
public FileJacket toOptimizedXls(Date start, Date end) {
    SubMonitor m = monitorFactory.newSubMonitor("Generating Report", 25);
    m.message("Loading Credit Memos");
    UniqueUnitEao unitEao = new UniqueUnitEao(uuEm);
    List<Object[]> rows = new ArrayList<>();
    List<Document> documents = new DocumentEao(redTapeEm).findDocumentsBetweenDates(start, end, DocumentType.CREDIT_MEMO, DocumentType.ANNULATION_INVOICE);
    m.setWorkRemaining(documents.size());
    for (Document document : documents) {
        String salesDate = SimpleDateFormat.getDateInstance(SimpleDateFormat.SHORT, Locale.GERMANY).format(document.getActual());
        UiCustomer customer = customerService.asUiCustomer(document.getDossier().getCustomerId());
        double price = 0;
        double afterTaxPrice = 0;
        boolean full = true;
        String sopos = "";
        for (Position position : document.getPositions().values()) {
            if (position.getType() == PositionType.COMMENT)
                continue;
            if (position.getType() == PositionType.UNIT || position.getType() == PositionType.UNIT_ANNEX) {
                full = position.getType() == PositionType.UNIT;
                String refurbishId = unitEao.findById(position.getUniqueUnitId()).getRefurbishId();
                sopos += (sopos.isEmpty()) ? refurbishId : " ," + refurbishId;
            } else if (position.getType() == PositionType.SHIPPING_COST) {
                Document invoice = document.getDossier().getActiveDocuments(DocumentType.INVOICE).get(0);
                SortedMap<Integer, Position> positions = invoice.getPositions(PositionType.SHIPPING_COST);
                if (positions.size() > 0) {
                    Position get = positions.get(positions.firstKey());
                    if (Math.abs(Math.abs(get.getPrice()) - Math.abs(position.getPrice())) > 0.001)
                        full = false;
                }
            }
            price += position.getPrice();
            afterTaxPrice += position.toAfterTaxPrice();
        }
        rows.add(new Object[] { document.getDossier().getIdentifier(), customer.getId(), salesDate, document.getIdentifier(), (full) ? "V" : "T", price, afterTaxPrice, customer.getCompany(), customer.toNameLine(), sopos });
        m.worked(1);
    }
    m.message("Generating Document");
    m.setWorkRemaining(10);
    STable table = new STable();
    table.setTableFormat(new CFormat(BLACK, WHITE, new CBorder(BLACK)));
    table.setHeadlineFormat(new CFormat(CFormat.FontStyle.BOLD, Color.BLACK, Color.YELLOW, CFormat.HorizontalAlignment.LEFT, CFormat.VerticalAlignment.BOTTOM, CFormat.Representation.DEFAULT));
    table.add(new STableColumn("DossierId", 15)).add(new STableColumn("Kid", 10)).add(new STableColumn("Belegdatum", 10));
    table.add(new STableColumn("DokumentId", 15)).add(new STableColumn("Voll/Teil", 10));
    table.add(new STableColumn("Netto", 10, new CFormat(CFormat.HorizontalAlignment.RIGHT, CFormat.Representation.CURRENCY_EURO)));
    table.add(new STableColumn("Brutto", 10, new CFormat(CFormat.HorizontalAlignment.RIGHT, CFormat.Representation.CURRENCY_EURO)));
    table.add(new STableColumn("Firma", 25)).add(new STableColumn("Name", 25)).add(new STableColumn("SopoNr.", 10));
    table.setModel(new STableModelList(rows));
    CCalcDocument cdoc = new TempCalcDocument("Gutschriften_");
    cdoc.add(new CSheet("Sheet1", table));
    File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
    m.finish();
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd_MM_yyy");
    return new FileJacket("Gutschriften_" + dateFormat.format(start) + "-" + dateFormat.format(end), ".xls", file);
}
Also used : DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) CCalcDocument(eu.ggnet.lucidcalc.CCalcDocument) CSheet(eu.ggnet.lucidcalc.CSheet) TempCalcDocument(eu.ggnet.lucidcalc.TempCalcDocument) CCalcDocument(eu.ggnet.lucidcalc.CCalcDocument) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) FileJacket(eu.ggnet.dwoss.util.FileJacket) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) STableColumn(eu.ggnet.lucidcalc.STableColumn) STable(eu.ggnet.lucidcalc.STable) STableModelList(eu.ggnet.lucidcalc.STableModelList) TempCalcDocument(eu.ggnet.lucidcalc.TempCalcDocument) CFormat(eu.ggnet.lucidcalc.CFormat) UiCustomer(eu.ggnet.dwoss.customer.opi.UiCustomer) CBorder(eu.ggnet.lucidcalc.CBorder) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with DocumentEao

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

the class CreditMemoReporterOperation method toXls.

@Override
public FileJacket toXls(Date start, Date end) {
    SubMonitor m = monitorFactory.newSubMonitor("Generating Report", 25);
    m.message("Loading Credit Memos");
    List<Position> creditMemoPositions = new ArrayList<>();
    for (Document document : new DocumentEao(redTapeEm).findDocumentsBetweenDates(start, end, DocumentType.COMPLAINT, DocumentType.CREDIT_MEMO, DocumentType.ANNULATION_INVOICE)) {
        for (Position position : document.getPositions().values()) {
            creditMemoPositions.add(position);
        }
    }
    m.setWorkRemaining(creditMemoPositions.size() * 2);
    UniqueUnitEao unitEao = new UniqueUnitEao(uuEm);
    m.message(null);
    List<Object[]> rows = new ArrayList<>();
    for (Position position : creditMemoPositions) {
        if (position.getType() == PositionType.COMMENT)
            continue;
        Document doc = position.getDocument();
        UiCustomer customer = customerService.asUiCustomer(position.getDocument().getDossier().getCustomerId());
        UniqueUnit unit = unitEao.findById(position.getUniqueUnitId());
        String error = "ERROR FINDING UNIT";
        String sopoNr = "-";
        String serial = "-";
        String contractor = "-";
        String fullOrPartial = "-";
        double customerPrice = 0;
        double retailerPrice = 0;
        if (position.getType() == PositionType.UNIT || position.getType() == PositionType.UNIT_ANNEX) {
            if (unit == null) {
                sopoNr = error;
                serial = error;
                contractor = error;
            } else {
                sopoNr = unit.getIdentifier(UniqueUnit.Identifier.REFURBISHED_ID);
                serial = unit.getIdentifier(UniqueUnit.Identifier.SERIAL);
                contractor = unit.getContractor().getName();
                customerPrice = unit.getPrice(PriceType.CUSTOMER);
                retailerPrice = unit.getPrice(PriceType.RETAILER);
                fullOrPartial = (position.getType() == PositionType.UNIT ? "V" : "T");
                if (position.getDocument().getType() == DocumentType.COMPLAINT)
                    fullOrPartial = "Rekla";
            }
        }
        rows.add(new Object[] { sopoNr, serial, position.getName(), contractor, fullOrPartial, position.getPrice(), position.toAfterTaxPrice(), position.getDocument().getDossier().getIdentifier(), doc.getActual(), position.getDocument().getIdentifier(), customer.getId(), customer.toNameCompanyLine(), customerPrice, retailerPrice });
        m.worked(5);
    }
    Collections.sort(rows, comperator);
    m.message("Generating Document");
    m.setWorkRemaining(10);
    STable table = new STable();
    table.setTableFormat(new CFormat(BLACK, WHITE, new CBorder(BLACK)));
    table.setHeadlineFormat(new CFormat(CFormat.FontStyle.BOLD, Color.BLACK, Color.YELLOW, CFormat.HorizontalAlignment.LEFT, CFormat.VerticalAlignment.BOTTOM, CFormat.Representation.DEFAULT));
    table.add(new STableColumn("SopoNr", 15)).add(new STableColumn("Seriennummer", 30)).add(new STableColumn("Name", 50)).add(new STableColumn("Contractor", 15)).add(new STableColumn("Voll/Teil", 10)).add(new STableColumn("Netto", 10, EURO)).add(new STableColumn("Brutto", 10, EURO)).add(new STableColumn("DossierId", 15)).add(new STableColumn("Belegdatum", 10, new CFormat(SHORT_DATE))).add(new STableColumn("DokumentId", 15)).add(new STableColumn("Kid", 10)).add(new STableColumn("Kunde", 50)).add(new STableColumn("Endkundenpreis(Netto)", 25, EURO)).add(new STableColumn("Händlerpreis(Netto)", 25, EURO));
    table.setModel(new STableModelList(rows));
    CCalcDocument cdoc = new TempCalcDocument("Gutschriften_");
    cdoc.add(new CSheet("Sheet1", table));
    File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
    m.finish();
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd_MM_yyy");
    return new FileJacket("Gutschriften_" + dateFormat.format(start) + "-" + dateFormat.format(end), ".xls", file);
}
Also used : DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) Position(eu.ggnet.dwoss.redtape.ee.entity.Position) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) CCalcDocument(eu.ggnet.lucidcalc.CCalcDocument) CSheet(eu.ggnet.lucidcalc.CSheet) TempCalcDocument(eu.ggnet.lucidcalc.TempCalcDocument) CCalcDocument(eu.ggnet.lucidcalc.CCalcDocument) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) FileJacket(eu.ggnet.dwoss.util.FileJacket) UniqueUnitEao(eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao) STableColumn(eu.ggnet.lucidcalc.STableColumn) UniqueUnit(eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit) STable(eu.ggnet.lucidcalc.STable) STableModelList(eu.ggnet.lucidcalc.STableModelList) TempCalcDocument(eu.ggnet.lucidcalc.TempCalcDocument) CFormat(eu.ggnet.lucidcalc.CFormat) UiCustomer(eu.ggnet.dwoss.customer.opi.UiCustomer) CBorder(eu.ggnet.lucidcalc.CBorder) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Example 5 with DocumentEao

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

the class DirectDebitReporterOperation method toXls.

/**
 * Creates the Report
 * <p/>
 * @return a ByteArray represeting the content of an xls file.
 */
@Override
public FileJacket toXls() {
    SubMonitor m = monitorFactory.newSubMonitor("Lastschriften", 25);
    m.worked(10);
    DocumentEao docEao = new DocumentEao(redTapeEm);
    List<Document> documents = docEao.findInvoiceUnpaid(DIRECT_DEBIT);
    Set<Long> customers = new HashSet<>();
    for (Document document : documents) {
        customers.add(document.getDossier().getCustomerId());
    }
    for (Long customerId : customers) {
        documents.addAll(docEao.findUnBalancedAnulation(customerId, DIRECT_DEBIT));
    }
    List<Object[]> rows = new ArrayList<>();
    for (Document doc : documents) {
        UiCustomer customer = customerService.asUiCustomer(doc.getDossier().getCustomerId());
        rows.add(new Object[] { doc.getDossier().getIdentifier(), customer.getId(), customer.toNameCompanyLine(), doc.getDirective().getName(), DocumentFormater.toConditions(doc), doc.getIdentifier(), doc.getActual(), doc.getPrice(), doc.toAfterTaxPrice(), doc.getDossier().getComment(), customerService.asCustomerMetaData(customer.getId()).getEmail() });
    }
    m.worked(10);
    STable table = new STable();
    table.setTableFormat(new CFormat(BLACK, WHITE, new CBorder(BLACK)));
    table.setHeadlineFormat(new CFormat(BOLD_ITALIC, WHITE, BLUE, CENTER, new CBorder(BLACK)));
    table.add(new STableColumn("Vorgang", 10)).add(new STableColumn("KID", 8)).add(new STableColumn("Kunde", 40));
    table.add(new STableColumn("Anweisung", 35)).add(new STableColumn("Status", 20)).add(new STableColumn("Dokument", 15)).add(new STableColumn("Datum", 15, new CFormat(SHORT_DATE)));
    table.add(new STableColumn("Netto", 15, new CFormat(RIGHT, CURRENCY_EURO))).add(new STableColumn("Brutto", 15, new CFormat(RIGHT, CURRENCY_EURO)));
    table.add(new STableColumn("Bemerkung", 50)).add(new STableColumn("eMail", 50));
    table.setModel(new STableModelList(rows));
    CCalcDocument cdoc = new TempCalcDocument("Lastschriften");
    cdoc.add(new CSheet("Sheet1", table));
    File file = LucidCalc.createWriter(LucidCalc.Backend.XLS).write(cdoc);
    FileJacket result = new FileJacket("Lastschriften", ".xls", file);
    m.finish();
    return result;
}
Also used : DocumentEao(eu.ggnet.dwoss.redtape.ee.eao.DocumentEao) SubMonitor(eu.ggnet.dwoss.progress.SubMonitor) Document(eu.ggnet.dwoss.redtape.ee.entity.Document) FileJacket(eu.ggnet.dwoss.util.FileJacket) UiCustomer(eu.ggnet.dwoss.customer.opi.UiCustomer) File(java.io.File)

Aggregations

DocumentEao (eu.ggnet.dwoss.redtape.ee.eao.DocumentEao)21 Document (eu.ggnet.dwoss.redtape.ee.entity.Document)14 SubMonitor (eu.ggnet.dwoss.progress.SubMonitor)7 DocumentHistory (eu.ggnet.dwoss.redtape.ee.entity.DocumentHistory)6 FileJacket (eu.ggnet.dwoss.util.FileJacket)6 UiCustomer (eu.ggnet.dwoss.customer.opi.UiCustomer)5 File (java.io.File)5 UniqueUnitEao (eu.ggnet.dwoss.uniqueunit.ee.eao.UniqueUnitEao)4 Test (org.junit.Test)4 CBorder (eu.ggnet.lucidcalc.CBorder)3 CCalcDocument (eu.ggnet.lucidcalc.CCalcDocument)3 CFormat (eu.ggnet.lucidcalc.CFormat)3 CSheet (eu.ggnet.lucidcalc.CSheet)3 STable (eu.ggnet.lucidcalc.STable)3 STableColumn (eu.ggnet.lucidcalc.STableColumn)3 STableModelList (eu.ggnet.lucidcalc.STableModelList)3 TempCalcDocument (eu.ggnet.lucidcalc.TempCalcDocument)3 Position (eu.ggnet.dwoss.redtape.ee.entity.Position)2 StockUnit (eu.ggnet.dwoss.stock.ee.entity.StockUnit)2 UniqueUnit (eu.ggnet.dwoss.uniqueunit.ee.entity.UniqueUnit)2